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 27D9AC4332F for ; Thu, 10 Nov 2022 08:37:19 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 41E826B0071; Thu, 10 Nov 2022 03:37:19 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 3CDB46B0072; Thu, 10 Nov 2022 03:37:19 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 295106B0074; Thu, 10 Nov 2022 03:37:19 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id 17D976B0071 for ; Thu, 10 Nov 2022 03:37:19 -0500 (EST) Received: from smtpin17.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id E3333AA9DD for ; Thu, 10 Nov 2022 08:37:18 +0000 (UTC) X-FDA: 80116878156.17.3E75D02 Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.220.28]) by imf28.hostedemail.com (Postfix) with ESMTP id 4FD2DC0007 for ; Thu, 10 Nov 2022 08:37:18 +0000 (UTC) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id BD46233921; Thu, 10 Nov 2022 08:37:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_rsa; t=1668069436; 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=6V5hKKGu3v1+LAYo3Y1CZXcFGnq/6skCmrLZL7X5ZHA=; b=y1tUkKJzhASIt8eQwU/QPh+wy6Uvi8vX2zmgPtIlnc5+UhL+7quEhEdom0BEDM0Z6yxEPJ 82T00CKq6ifLDvdMthBxRhxq0QlOaWe10rYHyc8Csrrjn5hliSpWi9j4tnn7EaoJYSUYRY x2J1aptazPYI5qGhwshyaWb62oa7JNU= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_ed25519; t=1668069436; 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=6V5hKKGu3v1+LAYo3Y1CZXcFGnq/6skCmrLZL7X5ZHA=; b=YufNe2XWyz5tA6lJ/MTKEBMVScc/94PlCqN68PhDYC5HVn1mpAem2HvcyoLTWBIrpJy2wQ rUH3ejKrflcKxoBA== Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id 8AD121332F; Thu, 10 Nov 2022 08:37:16 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id T5UIITy4bGNERgAAMHmgww (envelope-from ); Thu, 10 Nov 2022 08:37:16 +0000 Message-ID: <8e4080f8-7021-1c02-56cf-a105a5141abd@suse.cz> Date: Thu, 10 Nov 2022 09:37:16 +0100 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.4.1 Subject: Re: [PATCHv2] mm: slab: comment __GFP_ZERO case for kmem_cache_alloc Content-Language: en-US To: Alexander Aring Cc: cl@linux.com, penberg@kernel.org, rientjes@google.com, iamjoonsoo.kim@lge.com, akpm@linux-foundation.org, roman.gushchin@linux.dev, 42.hyeyoo@gmail.com, linux-mm@kvack.org, linux-kernel@vger.kernel.org, cluster-devel@redhat.com References: <20221011145413.8025-1-aahringo@redhat.com> <931c87d8-5856-e393-7108-66275ee4099a@suse.cz> From: Vlastimil Babka In-Reply-To: Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1668069438; 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=6V5hKKGu3v1+LAYo3Y1CZXcFGnq/6skCmrLZL7X5ZHA=; b=7yYS6Yz+Ngv7WDd4lMaXE/Iv7DA7vKlURzYP/cGP5aKCgYCGdzateIXVVEb7uIEuA4K7Qh jN3kCZLlQeO+tjmHxn+DQa7N6fUoSXFSW2CUS633gd/F6nQ+7XkD32di7PDgNKBBTpVlXa lGi24mv+X7RMpSPFUtgu+Df5ZpPJMzI= ARC-Authentication-Results: i=1; imf28.hostedemail.com; dkim=pass header.d=suse.cz header.s=susede2_rsa header.b=y1tUkKJz; dkim=pass header.d=suse.cz header.s=susede2_ed25519 header.b=YufNe2XW; spf=pass (imf28.hostedemail.com: domain of vbabka@suse.cz designates 195.135.220.28 as permitted sender) smtp.mailfrom=vbabka@suse.cz; dmarc=none ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1668069438; a=rsa-sha256; cv=none; b=5xaj+cG9qvQmx6WE6YgmZgy6JuMwER3ry0TXd6SO6utiuVAfGPBAPjpV6clniWZI/ULmNJ 5uXCqH2b5hMjqKUgKoH9RWi7e5+riozpJ6CocTADIMFgFk0bsoBxs70GkjhkJIWvNDNwip vFBA/WdFC3l9cRib9Zztvxyt/rBeZHM= X-Rspamd-Queue-Id: 4FD2DC0007 Authentication-Results: imf28.hostedemail.com; dkim=pass header.d=suse.cz header.s=susede2_rsa header.b=y1tUkKJz; dkim=pass header.d=suse.cz header.s=susede2_ed25519 header.b=YufNe2XW; spf=pass (imf28.hostedemail.com: domain of vbabka@suse.cz designates 195.135.220.28 as permitted sender) smtp.mailfrom=vbabka@suse.cz; dmarc=none X-Rspamd-Server: rspam10 X-Rspam-User: X-Stat-Signature: 3s54g9rhquq4caxhrgtdmhky3byqjgjp X-HE-Tag: 1668069438-188707 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: On 10/14/22 13:59, Alexander Aring wrote: > Hi, > > On Fri, Oct 14, 2022 at 3:35 AM Vlastimil Babka wrote: >> >> On 10/11/22 16:54, Alexander Aring wrote: >> > This patch will add a comment for the __GFP_ZERO flag case for >> > kmem_cache_alloc(). As the current comment mentioned that the flags only >> > matters if the cache has no available objects it's different for the >> > __GFP_ZERO flag which will ensure that the returned object is always >> > zeroed in any case. >> > >> > I have the feeling I run into this question already two times if the >> > user need to zero the object or not, but the user does not need to zero >> > the object afterwards. However another use of __GFP_ZERO and only zero >> > the object if the cache has no available objects would also make no >> > sense. >> >> Hmm, but even with the update, the comment is still rather misleading, no? >> - can the caller know if the cache has available objects and thus the flags >> are irrelevant, in order to pass flags that are potentially wrong (if there >> were no objects)? Not really. > > No, the caller cannot know it and that's why __GFP_ZERO makes no sense > if they matter only if the cache has no available objects. > >> - even if cache has available objects, we'll always end up in >> slab_pre_alloc_hook doing might_alloc(flags) which will trigger warnings >> (given CONFIG_DEBUG_ATOMIC_SLEEP etc.) if the flags are inappropriate for >> given context. So they are still "relevant" >> > > yes, so they are _always_ relevant in the current implementation. Also > as you said the user doesn't know when they become relevant or not.. > >> So maybe just delete the whole comment? slub.c doesn't have it, and if any >> such comment should exist for kmem_cache_alloc() and contain anything useful >> and not misleading, it should be probably in include/linux/slab.h anyway? >> > > ctags brought me there, but this isn't a real argument why it should > not be in the header file... > > I am not sure about deleting the whole comment as people have an vague > idea about how kmem_cache works and still need to know for __GFP_ZERO > that it will always zero the memory, but thinking again somebody will > make the conclusion it does not make sense as the user doesn't know > when objects are reused or allocated. Having that in mind and reading > the current comment was making me do more investigations into the > internal behaviour to figure out how it works regarding __GFP_ZERO. So, I did the following, which IMHO resolves the misleading parts and also mentions __GFP_ZERO. Sounds OK? https://git.kernel.org/pub/scm/linux/kernel/git/vbabka/slab.git/commit/?h=slab/for-6.2/cleanups&id=d6a3a7c3f65dfebcbc4872d5912d3465c8e8b051