From mboxrd@z Thu Jan 1 00:00:00 1970 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 0301FC48297 for ; Fri, 9 Feb 2024 10:36:05 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 160916B0072; Fri, 9 Feb 2024 05:36:05 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 1108D6B0075; Fri, 9 Feb 2024 05:36:05 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id EF3BB6B0078; Fri, 9 Feb 2024 05:36:04 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id DE07A6B0072 for ; Fri, 9 Feb 2024 05:36:04 -0500 (EST) Received: from smtpin25.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id AE4D7140F8C for ; Fri, 9 Feb 2024 10:36:04 +0000 (UTC) X-FDA: 81771910248.25.68FD533 Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.223.131]) by imf23.hostedemail.com (Postfix) with ESMTP id 81AF2140024 for ; Fri, 9 Feb 2024 10:36:02 +0000 (UTC) Authentication-Results: imf23.hostedemail.com; dkim=pass header.d=suse.cz header.s=susede2_rsa header.b=q8EFVpFD; dkim=pass header.d=suse.cz header.s=susede2_ed25519 header.b=Os5irXoj; dkim=pass header.d=suse.cz header.s=susede2_rsa header.b=q8EFVpFD; dkim=pass header.d=suse.cz header.s=susede2_ed25519 header.b=Os5irXoj; dmarc=none; spf=pass (imf23.hostedemail.com: domain of vbabka@suse.cz designates 195.135.223.131 as permitted sender) smtp.mailfrom=vbabka@suse.cz ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1707474962; a=rsa-sha256; cv=none; b=JxhBxUK0+WDhjhbiZFX33zIsv9nD/LOAKyICr7MdpIDQYbw0w5QA7frAJqNyQ3fvFzn6MU vDsVC1eR2M2Uty48IZJMC5KFuiFBsKTPp42nx6HnfnsSCtNg6ewRBaw6JRhI5I906nwDyg 03Ml4hrPqZTROAvEKvIJTmhEKmO4nrE= ARC-Authentication-Results: i=1; imf23.hostedemail.com; dkim=pass header.d=suse.cz header.s=susede2_rsa header.b=q8EFVpFD; dkim=pass header.d=suse.cz header.s=susede2_ed25519 header.b=Os5irXoj; dkim=pass header.d=suse.cz header.s=susede2_rsa header.b=q8EFVpFD; dkim=pass header.d=suse.cz header.s=susede2_ed25519 header.b=Os5irXoj; dmarc=none; spf=pass (imf23.hostedemail.com: domain of vbabka@suse.cz designates 195.135.223.131 as permitted sender) smtp.mailfrom=vbabka@suse.cz ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1707474962; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=CcVbW1YWRxlwtAlxxVM+tHjAbZLmle5oLxZZryL/4Q4=; b=WmIkqDMqf2vbBO+JkuQwsthfC3fKNliMZXgrKYKXqc8T/GO5c7Eappcog+umumk7I2hh7l XrwfXuhs6wiJSxTDqzDmIsk3wAA2bJaCPc6rp/1ycmIK9X+KSKQCcm8xqoF14tk08LqlbM lLlL8C8wcYnJIpefnHMVrjXL/Rab2iQ= Received: from imap1.dmz-prg2.suse.org (imap1.dmz-prg2.suse.org [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-out2.suse.de (Postfix) with ESMTPS id 58E481F7F9; Fri, 9 Feb 2024 10:36:00 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_rsa; t=1707474960; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=CcVbW1YWRxlwtAlxxVM+tHjAbZLmle5oLxZZryL/4Q4=; b=q8EFVpFDw9dBgosp01DFkZap7fNtlLm5KB3Yqj6BMUfvzTRqaVWvbMFsk1Mr/Kbam0lrR1 vP37oLX2zf5t7fDTC/ZcIOZ0mGfm675Ej3wfg7XA9WIYJY9iIs5R+b3+FBeyFi1DmKcaJH h0tqfIms63b8UQDBtauX9JlxKbdzSZI= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_ed25519; t=1707474960; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=CcVbW1YWRxlwtAlxxVM+tHjAbZLmle5oLxZZryL/4Q4=; b=Os5irXojjBx4PDCGsSrsWJiIoxn+kJwzlJbPDk7dqi0Kq0x34aWd6jkejI21wQ/3FYDGcL H4MOHe/OcndFNEBw== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_rsa; t=1707474960; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=CcVbW1YWRxlwtAlxxVM+tHjAbZLmle5oLxZZryL/4Q4=; b=q8EFVpFDw9dBgosp01DFkZap7fNtlLm5KB3Yqj6BMUfvzTRqaVWvbMFsk1Mr/Kbam0lrR1 vP37oLX2zf5t7fDTC/ZcIOZ0mGfm675Ej3wfg7XA9WIYJY9iIs5R+b3+FBeyFi1DmKcaJH h0tqfIms63b8UQDBtauX9JlxKbdzSZI= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_ed25519; t=1707474960; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=CcVbW1YWRxlwtAlxxVM+tHjAbZLmle5oLxZZryL/4Q4=; b=Os5irXojjBx4PDCGsSrsWJiIoxn+kJwzlJbPDk7dqi0Kq0x34aWd6jkejI21wQ/3FYDGcL H4MOHe/OcndFNEBw== 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 48DA51326D; Fri, 9 Feb 2024 10:36:00 +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 U/lvERAAxmUzJwAAD6G6ig (envelope-from ); Fri, 09 Feb 2024 10:36:00 +0000 Message-ID: Date: Fri, 9 Feb 2024 11:36:00 +0100 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH 1/3] mm: introduce memalloc_flags_{save,restore} Content-Language: en-US To: Kent Overstreet , linux-mm@kvack.org Cc: Matthew Wilcox , Michal Hocko , "Darrick J . Wong" References: <20240206215016.961253-1-kent.overstreet@linux.dev> <20240206215016.961253-2-kent.overstreet@linux.dev> From: Vlastimil Babka In-Reply-To: <20240206215016.961253-2-kent.overstreet@linux.dev> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Rspam-User: X-Rspamd-Server: rspam06 X-Rspamd-Queue-Id: 81AF2140024 X-Stat-Signature: kp9ad9jajhybjssrifubb1gg7rgwgg1j X-HE-Tag: 1707474962-560084 X-HE-Meta: U2FsdGVkX1+hmXESRmzt24ErnIlNAB+i4bc5/Ji2ibBFgkw1VQlvLn/tHGLNOdJHVl7TPKfuYvDi3qMkZ9VErVlNZV2KF+2GhCaZfnSyk00XFE4koxPYEvyphCaFlT7pRSVpTWld8y1MxaYc9su6oGRhpKP09Sz2QG8KRd40nl1v9oLmyhjk8nFbPcscNl3bmhpskEWqlQ1lliHyuxy0QQhZF/EOGcFSjM0gFk7dcA4O1lldHwmMdiX/g1g/ytdEFm0nOF0IaRnguHj+pS1L9xsyPhupLriUfYXwSULS7k9mldrX5z7VH3wuNjoFE1qAeqwGB6fUceXyrZ0hPUbWtQ82R9cM/TNrPRaet3MJrXJSi0du7oSaGhMdqkOlSfaQ/2Oqqq/KuBHD2bwk7sqQ3/TiapQc4CEvst4YbwT5p9/b0+6NhTcVF+a+eEmjUMqlwTfNyjisAvwR91nR92la3SAhnkcqHXcGJ/wTDuNZ/gA6NKDDEGYiV/D5qTKbB3W77YIJZTWyRNA57Kjhio2jjAdZqM6p2zJ3ZLBdHeGGkdCCOIqfs+e15GXOxreVY3YnUssbdH4qVolHGlr6pXOnonrVBW8XzGmqLZX0d/mHINAF55lyrsMO24Cc3dq7LYWZW01zvqxT9ME+/PBNxvlaRS+4errec1hlLXGgnCiGdbCTnjY4jGxHD1IF4+mrzJAMP5It8yHUCBYzfqX+AnFNw8sgak1mWY6zTrnNO5M43AP9zmgW3UcfWc7X5Y3O0CI6nBX+1xYEPrVf22Gg8GcsFDi/WoUYBL8+OkwlftoliJpeBe/e7P2p2vo8f7xEevuMiBpgQyYj9qWrpBVgC6BRyf2uCix9ahqdjQxGFifsARAJTMpKZFTaAPVj/pxKNs0rzGP5mgeNG/GXu4ALuEnQNTttUzWKULM39A37e9CQQ+K+d+weGmvdp6PST2YOfC+vFrvaOtCa5hJWwg7urN3 HEDjG9Q5 vWEGkdhThwvumgTc= 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: On 2/6/24 22:50, Kent Overstreet wrote: > Our proliferation of memalloc_*_{save,restore} APIs is getting a bit > silly, this adds a generic version and converts the existing > save/restore functions to wrappers. > > Signed-off-by: Kent Overstreet > Cc: Vlastimil Babka > Cc: Matthew Wilcox > Cc: Michal Hocko > Cc: Darrick J. Wong > Cc: linux-mm@kvack.org Acked-by: Vlastimil Babka This will also make it possible to do combinations of flags in a single call, in case some ad-hoc combinations are needed only in few places that don't warrant a designated helper. > --- > include/linux/sched/mm.h | 43 ++++++++++++++++++++++++---------------- > 1 file changed, 26 insertions(+), 17 deletions(-) > > diff --git a/include/linux/sched/mm.h b/include/linux/sched/mm.h > index 9a19f1b42f64..f00d7ecc2adf 100644 > --- a/include/linux/sched/mm.h > +++ b/include/linux/sched/mm.h > @@ -306,6 +306,24 @@ static inline void might_alloc(gfp_t gfp_mask) > might_sleep_if(gfpflags_allow_blocking(gfp_mask)); > } > > +/** > + * memalloc_flags_save - Add a PF_* flag to current->flags, save old value > + * > + * This allows PF_* flags to be conveniently added, irrespective of current > + * value, and then the old version restored with memalloc_flags_restore(). > + */ > +static inline unsigned memalloc_flags_save(unsigned flags) > +{ > + unsigned oldflags = ~current->flags & flags; > + current->flags |= flags; > + return oldflags; > +} > + > +static inline void memalloc_flags_restore(unsigned flags) > +{ > + current->flags &= ~flags; > +} > + > /** > * memalloc_noio_save - Marks implicit GFP_NOIO allocation scope. > * > @@ -319,9 +337,7 @@ static inline void might_alloc(gfp_t gfp_mask) > */ > static inline unsigned int memalloc_noio_save(void) > { > - unsigned int flags = current->flags & PF_MEMALLOC_NOIO; > - current->flags |= PF_MEMALLOC_NOIO; > - return flags; > + return memalloc_flags_save(PF_MEMALLOC_NOIO); > } > > /** > @@ -334,7 +350,7 @@ static inline unsigned int memalloc_noio_save(void) > */ > static inline void memalloc_noio_restore(unsigned int flags) > { > - current->flags = (current->flags & ~PF_MEMALLOC_NOIO) | flags; > + memalloc_flags_restore(flags); > } > > /** > @@ -350,9 +366,7 @@ static inline void memalloc_noio_restore(unsigned int flags) > */ > static inline unsigned int memalloc_nofs_save(void) > { > - unsigned int flags = current->flags & PF_MEMALLOC_NOFS; > - current->flags |= PF_MEMALLOC_NOFS; > - return flags; > + return memalloc_flags_save(PF_MEMALLOC_NOFS); > } > > /** > @@ -365,32 +379,27 @@ static inline unsigned int memalloc_nofs_save(void) > */ > static inline void memalloc_nofs_restore(unsigned int flags) > { > - current->flags = (current->flags & ~PF_MEMALLOC_NOFS) | flags; > + memalloc_flags_restore(flags); > } > > static inline unsigned int memalloc_noreclaim_save(void) > { > - unsigned int flags = current->flags & PF_MEMALLOC; > - current->flags |= PF_MEMALLOC; > - return flags; > + return memalloc_flags_save(PF_MEMALLOC); > } > > static inline void memalloc_noreclaim_restore(unsigned int flags) > { > - current->flags = (current->flags & ~PF_MEMALLOC) | flags; > + memalloc_flags_restore(flags); > } > > static inline unsigned int memalloc_pin_save(void) > { > - unsigned int flags = current->flags & PF_MEMALLOC_PIN; > - > - current->flags |= PF_MEMALLOC_PIN; > - return flags; > + return memalloc_flags_save(PF_MEMALLOC_PIN); > } > > static inline void memalloc_pin_restore(unsigned int flags) > { > - current->flags = (current->flags & ~PF_MEMALLOC_PIN) | flags; > + memalloc_flags_restore(flags); > } > > #ifdef CONFIG_MEMCG