Received: by 2002:a05:6358:45e:b0:b5:b6eb:e1f9 with SMTP id 30csp1478946rwe; Thu, 1 Sep 2022 20:45:40 -0700 (PDT) X-Google-Smtp-Source: AA6agR6RRHWFWA+tuIm3cgF4B9XduFJm3XmBlnF9Wy6cT61uYsGf9m1PEdkhDq//ck0MfHKZnPoC X-Received: by 2002:a17:90b:4b47:b0:1f7:2e06:5752 with SMTP id mi7-20020a17090b4b4700b001f72e065752mr2604420pjb.187.1662090340343; Thu, 01 Sep 2022 20:45:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1662090340; cv=none; d=google.com; s=arc-20160816; b=dPgWSjzNumdGGrAdb2KyGLzHJwfuFdInUyd4YxKcGMcTiMLxNGkHhhjc4aNhVRbdxA mvKV9Go2oMtgK1s7zkNMeAb3YVyT6UGWXd46sZEQoED3CO6V0SBOj92YzLmV6W44WU2C OQMrK1ps2E0kVVqZd89XJRgLF+PdUf/jDr4xFd4pOBFFlW0S0YybueHc85kVsDzV6j+x yZZV9+s7ERFCk4MKbJaE4PPGU8uiMY/6ekVIh8GiGHMNc0Eae1FSg+nKjNBX4+DIbJ2r xcmSL14nPp7NgkVioILZ/dhbZB7lAFfPnIa1YN3CPE5uEeQhKFrsjSdbwv0JLexdbK5X kUiw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature :dkim-signature; bh=GL6+2GXh/2nFgXmYIP+TgmK2lf7e53/uu6BPJeJrYkk=; b=Dymw4Tj8Hn5uNumg+gCMSn4azYBcR+thCmf7qPKqZFCCk88o8K4+qkFgwpbe6MX6Jk YFGbOi9KJLvkUL+rKHq+/gaVCJbt8b2z0Yq11HoeaO0wHSsfqqaGPX33st8zv3C6dZ45 /IUwAjWO0G2NFpseoDIt6XO+LbMBF8+X+De7CYXEG0Wb0xNjOJ78WC5Sb5360GqfVmdO OlIHyKQaZ/tJworBrLPQCSlK+UJbR5vr/jYsNU1c4wi2kzIBe0h5iJ3QV3Wh4O/ZsMiC NL4TZ38z5dDaHQU8uEKTmCg3LDR+zmkkHHNiGDkUzGU+2pxTMGDw1CYUvgVz9oH8EgD/ dKrw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@suse.de header.s=susede2_rsa header.b=c2i8KzQ8; dkim=neutral (no key) header.i=@suse.de header.s=susede2_ed25519 header.b=4SFs+r8y; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=suse.de Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id g64-20020a636b43000000b0041ce62de18esi788545pgc.611.2022.09.01.20.45.28; Thu, 01 Sep 2022 20:45:40 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@suse.de header.s=susede2_rsa header.b=c2i8KzQ8; dkim=neutral (no key) header.i=@suse.de header.s=susede2_ed25519 header.b=4SFs+r8y; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=suse.de Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235080AbiIBD1d (ORCPT + 99 others); Thu, 1 Sep 2022 23:27:33 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37236 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231936AbiIBD1c (ORCPT ); Thu, 1 Sep 2022 23:27:32 -0400 Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.220.29]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B58C27B7AB for ; Thu, 1 Sep 2022 20:27:31 -0700 (PDT) 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-out2.suse.de (Postfix) with ESMTPS id E799E20A75; Fri, 2 Sep 2022 03:27:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1662089249; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=GL6+2GXh/2nFgXmYIP+TgmK2lf7e53/uu6BPJeJrYkk=; b=c2i8KzQ8CjCNmeiqeCs2dkxyL0C7tsH9J57mAqVWbpvn6qdyGJtR/dzoQr7P00J0OCRZYZ 2/x4ovmo8ydfg0Iu2pjVMGKdDM7dBIpdVhJUdtTP83c6MTWZMa6HRO6M2JD6YQNxBz122B jXP0U9NzA6LZ3I1IPVOhssxRtUw8ddY= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1662089249; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=GL6+2GXh/2nFgXmYIP+TgmK2lf7e53/uu6BPJeJrYkk=; b=4SFs+r8yuGPkKxb3Xezd3fRsc8GETcgz1nzpv2C3yPqUYycX0jwFIRKlcrTmYnnZUHb7VU eAo5XuVJcmlVC/AA== 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 3D49B13328; Fri, 2 Sep 2022 03:27:29 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id zr8aDCF4EWO9DAAAMHmgww (envelope-from ); Fri, 02 Sep 2022 03:27:29 +0000 Date: Fri, 2 Sep 2022 05:27:27 +0200 From: Oscar Salvador To: Marco Elver Cc: Andrew Morton , linux-kernel@vger.kernel.org, linux-mm@kvack.org, Michal Hocko , Vlastimil Babka , Eric Dumazet , Waiman Long , Suren Baghdasaryan , Alexander Potapenko , Andrey Konovalov , Dmitry Vyukov , kasan-dev@googlegroups.com Subject: Re: [PATCH 1/3] lib/stackdepot: Add a refcount field in stack_record Message-ID: References: <20220901044249.4624-1-osalvador@suse.de> <20220901044249.4624-2-osalvador@suse.de> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,SPF_HELO_NONE, SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Sep 01, 2022 at 10:24:58AM +0200, Marco Elver wrote: > On Thu, Sep 01, 2022 at 06:42AM +0200, Oscar Salvador wrote: > > include/linux/stackdepot.h | 13 ++++++- > > lib/stackdepot.c | 79 +++++++++++++++++++++++++++++++------- > > mm/kasan/common.c | 3 +- > > +Cc other kasan maintainers Yeah, sorry about that, I should have CCed you guys. > > +typedef enum stack_action { > > + STACK_ACTION_NONE, > > + STACK_ACTION_INC, > > +}stack_action_t; > > + > > missing space after '}'. But please no unnecessary typedef, just 'enum > stack_action' (and spelling out 'enum stack_action' elsewhere) is just > fine. Sure, will re-name it. > > This is in the global namespace, so I'd call this > stack_depot_action+STACK_DEPOT_ACTION_*. > > However, .._ACTION_INC doesn't really say what's incremented. As an > analog to stack_depot_dec_count(), perhaps .._ACTION_COUNT? I guess we can go "STACK_DEPOT_ACTION_COUNT", or "STACK_DEPOT_ACTION_REF_INC", but the latter seems rather baroque for my taste. > In general it'd be nicer if there was stack_depot_inc_count() instead of > this additional argument, but I see that for performance reasons you > might not like that? Yes, the first prototypes didn't have this stack_action_t thing, but that implied that we had to look for the stack twice in the __set_page_owner() case. This way we only do that in the __reset_page_owner() case. So yes, it's a trade-off performance vs LOC. > > --- a/lib/stackdepot.c > > +++ b/lib/stackdepot.c > > @@ -63,6 +63,7 @@ struct stack_record { > > u32 hash; /* Hash in the hastable */ > > u32 size; /* Number of frames in the stack */ > > union handle_parts handle; > > + refcount_t count; /* Number of the same repeated stacks */ > > This will increase stack_record size for every user, even if they don't > care about the count. > > Is there a way to store this out-of-line somewhere? That would require having some kind of e.g: dynamic struct and allocating new links to stacks as they were created and increase the refcount there. But that would be too much of complexity, I think. As I read in your other thread, we can probably live with that, but it is worth spelling out in the changelog. > > +void stack_depot_dec_count(depot_stack_handle_t handle) > > +{ > > + struct stack_record *stack = NULL; > > + > > + stack = stack_depot_getstack(handle); > > + if (stack) { > > + /* > > + * page_owner creates some stacks via create_dummy_stack(). > > + * We are not interested in those, so make sure we only decrement > > + * "valid" stacks. > > + */ > > Comment indent is wrong. Will fix it. Thanks for taking the time to review the code Marco! -- Oscar Salvador SUSE Labs