This phase I trial studies the best dose of copanlisib when given together with combination chemotherapy (R-GCD) in treating patients with diffuse large B-cell lymphoma that has come back (relapsed) or does not respond to treatment (refractory) or grade 3b follicular lymphoma that has come back (relapsed) after 1 prior line of therapy. Copanlisib may stop the growth of tumor cells by blocking some of the enzymes needed for cell growth. Rituximab is a monoclonal antibody that may interfere with the ability of cancer cells to grow and spread. Drugs used in chemotherapy, such as gemcitabine, carboplatin, and dexamethasone, work in different ways to stop the growth of tumor cells, either by killing the cells, by stopping them from dividing, or by stopping them from spreading. Giving copanlisib together with R-GCD as second line therapy may improve the complete response rate for patients with diffuse large B-cell lymphoma or follicular lymphoma.