From patchwork Tue Sep 17 15:53:52 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vitaly Wool X-Patchwork-Id: 11149013 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 727F3112B for ; Tue, 17 Sep 2019 15:53:58 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 3EF0D21852 for ; Tue, 17 Sep 2019 15:53:58 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="kAOn5Shr" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 3EF0D21852 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 5BC086B0003; Tue, 17 Sep 2019 11:53:57 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 592F96B0005; Tue, 17 Sep 2019 11:53:57 -0400 (EDT) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 4AA616B0006; Tue, 17 Sep 2019 11:53:57 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0122.hostedemail.com [216.40.44.122]) by kanga.kvack.org (Postfix) with ESMTP id 2BFE86B0003 for ; Tue, 17 Sep 2019 11:53:57 -0400 (EDT) Received: from smtpin14.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay04.hostedemail.com (Postfix) with SMTP id BB87883E2 for ; Tue, 17 Sep 2019 15:53:56 +0000 (UTC) X-FDA: 75944858472.14.fuel85_5c98c3774670e X-Spam-Summary: 2,0,0,35115a55249881d5,d41d8cd98f00b204,vitalywool@gmail.com,::akpm@linux-foundation.org:linux-kernel@vger.kernel.org:ddstreet@ieee.org:vbabka@suse.cz:markus.linnala@gmail.com,RULES_HIT:41:355:379:541:800:960:966:973:988:989:1260:1277:1311:1313:1314:1345:1437:1515:1516:1518:1534:1541:1593:1594:1711:1730:1747:1777:1792:2196:2199:2393:2553:2559:2562:3138:3139:3140:3141:3142:3353:3865:3866:3868:3870:3871:3872:3874:4321:4385:5007:6117:6261:6653:7514:7558:8603:9413:9592:10004:10400:10450:10455:11026:11473:11658:11914:12043:12297:12438:12517:12519:12555:12760:12895:13069:13221:13229:13311:13357:13439:13972:14096:14097:14181:14394:14659:14687:14721:19904:19999:21080:21444:21451:21627:21666:30054:30090,0,RBL:209.85.208.195:@gmail.com:.lbl8.mailshell.net-62.18.0.100 66.100.201.100,CacheIP:none,Bayesian:0.5,0.5,0.5,Netcheck:none,DomainCache:0,MSF:not bulk,SPF:fp,MSBL:0,DNSBL:neutral,Custom_rules:0:0:0,LFtime:26,LUA_SUMMARY:none X-HE-Tag: fuel85_5c98c3774670e X-Filterd-Recvd-Size: 4799 Received: from mail-lj1-f195.google.com (mail-lj1-f195.google.com [209.85.208.195]) by imf40.hostedemail.com (Postfix) with ESMTP for ; Tue, 17 Sep 2019 15:53:56 +0000 (UTC) Received: by mail-lj1-f195.google.com with SMTP id 7so4062361ljw.7 for ; Tue, 17 Sep 2019 08:53:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=date:from:to:cc:subject:message-id:mime-version :content-transfer-encoding; bh=2YOj06cPPvgsZx9maFNFvfyY5twtTMJtLzahT6UKWkM=; b=kAOn5ShrNvK4JRjqibsxIgC3tnVF3yLFi1pJnhx52obG35TjwggxRBvh7USQv2jDlh SaXa5YI0QDhVDM0XOtk2uIbz6dnWhZwPCnKx7aj/1dv5EwEEJhm24G5CSugX93SklLME 6ClLDZZvexTAhqhrhsnupobLStLlEZEIn0lVbIjpFCQ+VTRgmAS1lf0XFPM2tscrZIWi MUPhhPUnjkeAkQEzIvs8qXv9f+zwOWPRxKva89MthTxTIRNnnQvcXmOSlh0xq9pm+ysI wVLuqnzz39t3+DrPVleBmISEaUxgBdqhprHTOH9K/NQ+ozoqAHxtEJQnXnZIMvvLDbEd Ye2w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:mime-version :content-transfer-encoding; bh=2YOj06cPPvgsZx9maFNFvfyY5twtTMJtLzahT6UKWkM=; b=YA1Hv1K5/yGMV7w+CARBLyhE12HNcpXjrw9Z3/PUkFWuEbiVMTkKeiT8Mo59bQetpK 9+yG0CTdJh+2fLXyhkk7M0NjDa1WCkv5PxTXLNSo6D4bIxVa4uLQr2X5WkPoSIK6DFvX zJQ4rpE/dLIW4nu2xJkqriX+Dy7bwjQ2EjrHpenhjxZ0TDiU1XTyVST0rFaZutBu6aUt PlgRhsu2bIHd6Fj9dEybXw+BD8/zb2YEj6qjgWqO5FgKqOUmW6w9tC98aB91IgUKpm+H NjX3ZDsSBctU0antT68Gx1cekAF1UoIlDvdhnYsrPUsGqXYOa8KcC6XCzQnXIFih5PmV 7yuA== X-Gm-Message-State: APjAAAUDw6r73FKdxSaOjQGO98EzbKe2nBJT89xXRik0ao3wWhIOZPLa paRr23hTCvEIK1skrcrZYatFTOFsG0ecyw== X-Google-Smtp-Source: APXvYqxInzgwwA/H7snjGtaKT2ZKQl55koT6+1i82eeg1Fid52kHKD8WfWEvLiVsSbaoNPgPXI6hVA== X-Received: by 2002:a2e:9d0d:: with SMTP id t13mr2297429lji.169.1568735634420; Tue, 17 Sep 2019 08:53:54 -0700 (PDT) Received: from vitaly-Dell-System-XPS-L322X ([188.150.241.161]) by smtp.gmail.com with ESMTPSA id x76sm604083ljb.81.2019.09.17.08.53.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 17 Sep 2019 08:53:53 -0700 (PDT) Date: Tue, 17 Sep 2019 18:53:52 +0300 From: Vitaly Wool To: Linux-MM , Andrew Morton , linux-kernel@vger.kernel.org Cc: Dan Streetman , Vlastimil Babka , markus.linnala@gmail.com Subject: [PATCH] z3fold: fix memory leak in kmem cache Message-Id: <20190917185352.44cf285d3ebd9e64548de5de@gmail.com> X-Mailer: Sylpheed 3.5.1 (GTK+ 2.24.32; x86_64-pc-linux-gnu) Mime-Version: 1.0 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: Currently there is a leak in init_z3fold_page() -- it allocates handles from kmem cache even for headless pages, but then they are never used and never freed, so eventually kmem cache may get exhausted. This patch provides a fix for that. Reported-by: Markus Linnala Signed-off-by: Vitaly Wool --- mm/z3fold.c | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/mm/z3fold.c b/mm/z3fold.c index 6397725b5ec6..7dffef2599c3 100644 --- a/mm/z3fold.c +++ b/mm/z3fold.c @@ -301,14 +301,11 @@ static void z3fold_unregister_migration(struct z3fold_pool *pool) } /* Initializes the z3fold header of a newly allocated z3fold page */ -static struct z3fold_header *init_z3fold_page(struct page *page, +static struct z3fold_header *init_z3fold_page(struct page *page, bool headless, struct z3fold_pool *pool, gfp_t gfp) { struct z3fold_header *zhdr = page_address(page); - struct z3fold_buddy_slots *slots = alloc_slots(pool, gfp); - - if (!slots) - return NULL; + struct z3fold_buddy_slots *slots; INIT_LIST_HEAD(&page->lru); clear_bit(PAGE_HEADLESS, &page->private); @@ -316,6 +313,12 @@ static struct z3fold_header *init_z3fold_page(struct page *page, clear_bit(NEEDS_COMPACTING, &page->private); clear_bit(PAGE_STALE, &page->private); clear_bit(PAGE_CLAIMED, &page->private); + if (headless) + return zhdr; + + slots = alloc_slots(pool, gfp); + if (!slots) + return NULL; spin_lock_init(&zhdr->page_lock); kref_init(&zhdr->refcount); @@ -962,7 +965,7 @@ static int z3fold_alloc(struct z3fold_pool *pool, size_t size, gfp_t gfp, if (!page) return -ENOMEM; - zhdr = init_z3fold_page(page, pool, gfp); + zhdr = init_z3fold_page(page, bud == HEADLESS, pool, gfp); if (!zhdr) { __free_page(page); return -ENOMEM;