From patchwork Wed Jul 10 01:07:47 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Qu Wenruo X-Patchwork-Id: 13728758 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id CB94CC2BD09 for ; Wed, 10 Jul 2024 01:08:23 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 43F836B0092; Tue, 9 Jul 2024 21:08:23 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 3A4216B0096; Tue, 9 Jul 2024 21:08:23 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 1CF2D6B0098; Tue, 9 Jul 2024 21:08:23 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id E571A6B0092 for ; Tue, 9 Jul 2024 21:08:22 -0400 (EDT) Received: from smtpin21.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id 607021A1731 for ; Wed, 10 Jul 2024 01:08:22 +0000 (UTC) X-FDA: 82322057244.21.38EA48A Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.223.130]) by imf04.hostedemail.com (Postfix) with ESMTP id 444D74000C for ; Wed, 10 Jul 2024 01:08:20 +0000 (UTC) Authentication-Results: imf04.hostedemail.com; dkim=pass header.d=suse.com header.s=susede1 header.b=mNSU3tN3; dkim=pass header.d=suse.com header.s=susede1 header.b=mNSU3tN3; spf=pass (imf04.hostedemail.com: domain of wqu@suse.com designates 195.135.223.130 as permitted sender) smtp.mailfrom=wqu@suse.com; dmarc=pass (policy=quarantine) header.from=suse.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1720573685; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=NZ4IkQENG6pAsAvxDMHr6A4L6Cb8IoFDy31gJ/5zHnI=; b=vk8kipzG+L0jSfqMIBj2qlSYos2fDbl3aElUb7dh8USt+Q6s6+PP9Jka8eKFa8LpQpdslv CNZ58orY5hYpNaiKeZFYIsjWNgqKVKpDwnyxQgrYuRq3gIlaKdlI7M3pjE7ZRJADzRRcSs 1JTrYkmLybti7kS0niOB+z2arAcaxy8= ARC-Authentication-Results: i=1; imf04.hostedemail.com; dkim=pass header.d=suse.com header.s=susede1 header.b=mNSU3tN3; dkim=pass header.d=suse.com header.s=susede1 header.b=mNSU3tN3; spf=pass (imf04.hostedemail.com: domain of wqu@suse.com designates 195.135.223.130 as permitted sender) smtp.mailfrom=wqu@suse.com; dmarc=pass (policy=quarantine) header.from=suse.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1720573685; a=rsa-sha256; cv=none; b=gO701wCICn4PkEsvCSAqSrzQtTU1zL/cDFB0kPeVbeys0cmYsUYa+up44S/9/0xnr7X90i RzxAjTr8YCXSVWSdjLZ0AVy9XcwKrWbEl6FnGQanDveDtwW1WHsRDSlIirRICNTNiYyGA8 oIYzLmV9f9krWTif+eceYKosDvUQcAI= Received: from imap1.dmz-prg2.suse.org (imap1.dmz-prg2.suse.org [IPv6:2a07:de40:b281:104:10:150:64:97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id 0735E21992; Wed, 10 Jul 2024 01:08:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1720573699; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=NZ4IkQENG6pAsAvxDMHr6A4L6Cb8IoFDy31gJ/5zHnI=; b=mNSU3tN3Ou3EI19Z2tJFU6z1BKnlle3J30Z9sGaQw2KQjs2IaJI+jDFXPtU+geVVNzxWT4 vyvhTW2mse0zEn6UYfq1w87wwhv7anlh9DD6B7Vku5rPUmzzdT4E+rOPi+JwFDn60IDLnu IPDUFz3lzx6uCKyS0ZnCTJdoGN9eDiQ= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1720573699; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=NZ4IkQENG6pAsAvxDMHr6A4L6Cb8IoFDy31gJ/5zHnI=; b=mNSU3tN3Ou3EI19Z2tJFU6z1BKnlle3J30Z9sGaQw2KQjs2IaJI+jDFXPtU+geVVNzxWT4 vyvhTW2mse0zEn6UYfq1w87wwhv7anlh9DD6B7Vku5rPUmzzdT4E+rOPi+JwFDn60IDLnu IPDUFz3lzx6uCKyS0ZnCTJdoGN9eDiQ= Received: from imap1.dmz-prg2.suse.org (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by imap1.dmz-prg2.suse.org (Postfix) with ESMTPS id 8F5BC1369A; Wed, 10 Jul 2024 01:08:17 +0000 (UTC) Received: from dovecot-director2.suse.de ([2a07:de40:b281:106:10:150:64:167]) by imap1.dmz-prg2.suse.org with ESMTPSA id GPwQEgHfjWaYTQAAD6G6ig (envelope-from ); Wed, 10 Jul 2024 01:08:17 +0000 From: Qu Wenruo To: linux-btrfs@vger.kernel.org, linux-mm@kvack.org, linux-fsdevel@vger.kernel.org Subject: [PATCH 2/2] mm: allow certain address space to be not accounted by memcg Date: Wed, 10 Jul 2024 10:37:47 +0930 Message-ID: <92dea37a395781ee4d5cf8b16307801ccd8a5700.1720572937.git.wqu@suse.com> X-Mailer: git-send-email 2.45.2 In-Reply-To: References: MIME-Version: 1.0 X-Rspamd-Action: no action X-Rspamd-Server: rspam03 X-Rspam-User: X-Rspamd-Queue-Id: 444D74000C X-Stat-Signature: y84wph7febkaayxxyw9iumjrathcp63k X-HE-Tag: 1720573700-755568 X-HE-Meta: U2FsdGVkX1+ae9zkGoFT342uTxXubbUz5K9dez/zDV4mdCoM3/Mr8PRkTlwu8jU2vGpDhHN4+F6SCfajI+jBURzkPxqGIucOphBCUc/3WrXmnaFtIfnV332lcndQbdTkmDT9RAHAlmhvvOU/OWLBenVTFjc7ZE3++U60pgkv4Je20B1Vj3xXNfknTXl1ARkurBcjd8OrGvTij9SUjome+e+CrsvGbmqTOoRCovSw2xGgGIVuJ6PB2dbuTShuIEwxP2oE98XATfiflZYd1d7fs52TNpYwpMFegfseDKuwpQfuxKWxIzB8og3Lpfo6X3z2uMl/JVQ4UfB3yTA2UaufKI4DqzVGL4lZfZ1cO0HpXm1mQCxo/1P93hSEVBzMEhNCH6qHtGa9TMjFVL6zYqN0XNv+Vvi+L8yB7pihznXjkX8oePSS/x+LoWsn4F6XdJ9JjPlnrNhcHuyldgawuV22kmbDLodnXwbGiI0cALoXQRb59u/3UwKL/uypBUJQwvUSS652yCtEb76iLym1bcU0fSeYCdpScZ5quSUEn3+JMDPGVt4wahpKTYIacS3nWW5oZfcRwHQ5Cmu8H8GBr+NAS0WUflXBdPK9qMrnGmdTYjlcy4/z4IilRBoG+PqJoHZmyxuHI3bx3lMFs4EXV2zdMfB77WxAYBfamFrR33whH7D7nZ1V6OMBeaFZ7Um2z8JO7Oh3QteTPq6W3erbj8BCmc/6sJv3nP7kr6KPWKN3+Xc8g2QsAkVDvglTsElR7M2wjXOeVbdRf82Bck70UwwrWewbtpdbyhbcY4JyAltVV9Cgs1PzodRIKp91oCM98XXMSUBYADK7LqpQMY8pQpR6xCzFICg3CnixbScFFeokceebN/UzFSL+qPwI/dSK0hHkQ0EIn4dJMvfyt1791aZMOplftP1dCQOEiX1ts6zbrEsI0Y4Svl3SKHVVJbn1VhX+dSeIxrkiiXlPHTS8c0a RsOaUWtq Q37HdER7Tga2aUVFtJrH03Sq6kpLjcOtI8YLr9cqGRP5xOi9lk12VC4yVQQv8Xq+XZNnE/WgmVmgm9fr47HOyuOqIovB17UjJrHE0/EvkI1brq8vT+d76Aek9gQDC0m2OBxVG4mX2FDfkembh34JAswTM7E1JV6+mdQVbOuqlzjVexa6Wjc7FxucwC86pGh+1qizjwq+WSKuC68QndYBEu70FA7ZLhsvn8JIuQAjOYgZpKrBU5ZJJFVWUPz/sWxFRxwTXUhxITT9C8MM= 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: List-Subscribe: List-Unsubscribe: Currently any page/folio added to an address space will be accounted by memcg. However this is not always true for certain address spaces. One example is the address space of btrfs btree inode, which stores the metadata of one btrfs. Currently btrfs is using __GFP_NOFAIL for all operations touching that address space, but this can has other problems as __GFP_NOFAIL can wait infinitely until the request is met. To avoid unnecessary memcg charge for the btree inode address space, introduce a new flag, AS_NO_MEMCG, to inform that folios added to that address space should not trigger memcg charge/uncharge, and add btrfs btree inode to utilize that new flag. Signed-off-by: Qu Wenruo --- fs/btrfs/disk-io.c | 1 + include/linux/pagemap.h | 1 + mm/filemap.c | 12 +++++++++--- 3 files changed, 11 insertions(+), 3 deletions(-) diff --git a/fs/btrfs/disk-io.c b/fs/btrfs/disk-io.c index 9e64e9fde832..2de9db95fbb9 100644 --- a/fs/btrfs/disk-io.c +++ b/fs/btrfs/disk-io.c @@ -1931,6 +1931,7 @@ static int btrfs_init_btree_inode(struct super_block *sb) inode->i_size = OFFSET_MAX; inode->i_mapping->a_ops = &btree_aops; mapping_set_gfp_mask(inode->i_mapping, GFP_NOFS); + set_bit(AS_NO_MEMCG, &inode->i_mapping->flags); extent_io_tree_init(fs_info, &BTRFS_I(inode)->io_tree, IO_TREE_BTREE_INODE_IO); diff --git a/include/linux/pagemap.h b/include/linux/pagemap.h index 59f1df0cde5a..d4634d5d5dab 100644 --- a/include/linux/pagemap.h +++ b/include/linux/pagemap.h @@ -209,6 +209,7 @@ enum mapping_flags { AS_STABLE_WRITES, /* must wait for writeback before modifying folio contents */ AS_UNMOVABLE, /* The mapping cannot be moved, ever */ + AS_NO_MEMCG, /* No memcg should be applied to this address space .*/ }; /** diff --git a/mm/filemap.c b/mm/filemap.c index 876cc64aadd7..a2282aa4f2a6 100644 --- a/mm/filemap.c +++ b/mm/filemap.c @@ -960,11 +960,17 @@ int filemap_add_folio(struct address_space *mapping, struct folio *folio, pgoff_t index, gfp_t gfp) { void *shadow = NULL; + const bool no_memcg = test_bit(AS_NO_MEMCG, &mapping->flags); int ret; - ret = mem_cgroup_charge(folio, NULL, gfp); - if (ret) - return ret; + if (!no_memcg) { + ret = mem_cgroup_charge(folio, NULL, gfp); + if (ret) + return ret; + } else { + /* The page should not has any memcg set for it. */ + VM_BUG_ON_FOLIO(folio_memcg(folio), folio); + } __folio_set_locked(folio); ret = __filemap_add_folio(mapping, folio, index, gfp, &shadow);