Received: by 2002:a05:7412:3b8b:b0:fc:a2b0:25d7 with SMTP id nd11csp1203532rdb; Fri, 9 Feb 2024 13:45:25 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCW7JC28NQkhbU9riNxQV0fUHJzHs9Eo4ii8Q3DULFk8+RZ3KBaisop9sdbdHom7ih5QxqHHKgfCRmPDn/tLmXbf85TJZ8nZzRlvTkwBkw== X-Google-Smtp-Source: AGHT+IHzyexeXztABhoSok3Rv6NE0hLr940BA+T8Dzsiwrtb0u1a2qY9LF+L1w18YGy7UjZQKodr X-Received: by 2002:a05:6808:1396:b0:3c0:8ee:7e72 with SMTP id c22-20020a056808139600b003c008ee7e72mr378087oiw.43.1707515124811; Fri, 09 Feb 2024 13:45:24 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707515124; cv=pass; d=google.com; s=arc-20160816; b=lfczQ5fNyRGvJl4QjyP7p9Srsj/oI9VBQM/bM/6OsDIvl6YyeHFZXbuW5khmFocQQm +yWKsslapirh0To7HrrQNzv8uamldVgRncaulq+egHhjbp+8V/KCoy3AXJIoLFAQj5Gs CE23ipUveSKo7JhNN2MdLhdSN16FEBlZbP1LlEpTBwA8ZhJu+npqG1XXYt0btAQVBU0S Qvz+DZ0GIC7zxzmSrOV+KGYA4ytppYdzqc60grM5Mura+5KF2ljFo1Aj03TLsL0mnH+m bpEmT7qcV6c4TzNIs7ix3O9Exz2+qwvXheT0U+ZtT1tOvreZN9+ThMaEWuSwPDbU9/L0 vw5Q== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:list-unsubscribe:list-subscribe:list-id:precedence :dkim-signature; bh=et8tU5mdHwkCQtGabHsU2uKDCRclXXg4309BFtdcuZo=; fh=vMJKsXOCK9iwiOvafNlzyv4JrJqOvSq1KvoXXWXtRSc=; b=FjnD3eTH8ZZwSkfAfANH7mciSb5Jq/LK90OpMESmgT47IxnQv2Ac3R8r1EVq0mqN0W n3f0mRQu/vHcSsNlpW+J9+jo17fk5eaIFnTO7I+Bn9pIDfVtheNRMNQDqxGrED710cBY hrfOOSTd5hcwrYp6y6q0+2Kv/2xCMQX9c4lhhC18HBKUaPrwFeL6Ui85R0DjYZ1BMZs/ s9trE7gIw8zkyMSyqIT/vRSJSUdQHtLP+9UOdt9tx7F31aCBG1JSZBO4FXKwERd5HZq/ ckUPQ6Azn/97ohsm8eMkSsNTHIJuo5eLllg2MbIopAAgB0yWkYZaiWIKDhpIQn35sDsG BNxA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=DvhpMrXg; arc=pass (i=1 spf=pass spfdomain=google.com dkim=pass dkdomain=google.com dmarc=pass fromdomain=google.com); spf=pass (google.com: domain of linux-kernel+bounces-60048-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-60048-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com X-Forwarded-Encrypted: i=2; AJvYcCU6bgjPNzBq4QcioRmJzI4qzM2lejGEQeND15Rcnh54aUbIkzUMvP2GgPmAx7CuD8l39YbVrklz7U+peiRwmkpd8lfdQK3ZuDDoeF0QzA== Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id f14-20020a05620a20ce00b007838d947f3csi381614qka.219.2024.02.09.13.45.24 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 09 Feb 2024 13:45:24 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-60048-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=DvhpMrXg; arc=pass (i=1 spf=pass spfdomain=google.com dkim=pass dkdomain=google.com dmarc=pass fromdomain=google.com); spf=pass (google.com: domain of linux-kernel+bounces-60048-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-60048-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id C7ABB1C23465 for ; Fri, 9 Feb 2024 21:45:09 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 273951A71B; Fri, 9 Feb 2024 21:45:03 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="DvhpMrXg" Received: from mail-vk1-f169.google.com (mail-vk1-f169.google.com [209.85.221.169]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C027C63B8 for ; Fri, 9 Feb 2024 21:45:00 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.169 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707515102; cv=none; b=t7Se5VICWVqOjMl4nNrPlbqG/RavpzGA+q/Uo7q53QCDF7f2RdPoofXMtHEWhDBr4jWepcfC9pdNqr11rnafrm1JoK4G2SaAa5KMhiuSEtem8ihKty+zvVIZPhrJ4bRsy2cVaF0oANLlrZWju836OE6dLFm9J5uNhqt8vXDgq/I= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707515102; c=relaxed/simple; bh=CCcqjaOfU78XPYHHJ5BCgwHxykBoRkB3PHAnaQWoiBk=; h=MIME-Version:References:In-Reply-To:From:Date:Message-ID:Subject: To:Cc:Content-Type; b=rSaTFqXM2oS6TxTKTfR9j+CFhWMqvDwC8rwb7ky/PMEsvSAoNps70lq9ZtIJzgCTpwwVf8ShS+zk5SY6jJ0tO0IHa6QCljqFqTP8qMsrIlfkulQHzSByN6i2Bsbb0wyHFypIzWwcHuGkDoi0QBPOyvP2C5l7kovV+9s+nbAqI5g= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=DvhpMrXg; arc=none smtp.client-ip=209.85.221.169 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=google.com Received: by mail-vk1-f169.google.com with SMTP id 71dfb90a1353d-4c035b3203dso364872e0c.2 for ; Fri, 09 Feb 2024 13:45:00 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1707515099; x=1708119899; darn=vger.kernel.org; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=et8tU5mdHwkCQtGabHsU2uKDCRclXXg4309BFtdcuZo=; b=DvhpMrXgxu/rBn/F/tunogFiTATcbk5JobbMpCFDJaprG4pxTSYG642cy2ubDkduAu hNjyRRsd7+u+Wk6t3e+qwmRZrolwkB3VzTCG8kCmVFuZDwyGoM41vgw8y+A4DCWuYv0C X4LsNY6SKYzSRXAtSvkmqVSUVwK97BtUXHn9legJtZ5He42w1prI8yrVe8j3Qf/fXiUk bPFMRTpIKjl/n15E8sqFYXHb7ufV+AB7UYqdkqHyND0y4sVpkB9pkalveM9nAdZWipiH SkC3dgX4wF8DrYq973X/yqFM8JfW1HoCljNkfIHHEV8/8TwPCb6wQ3Q5hGHox4kFqOVZ 4P5Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1707515099; x=1708119899; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=et8tU5mdHwkCQtGabHsU2uKDCRclXXg4309BFtdcuZo=; b=Tf4zgTkX+IHJrzjl4ZV+jmrk3WAL8R3tZ7xQafwDB7ui/T7SyX+dWyQ4SsMDV1tFe4 IzuPiEzrj6HHwAYozQpDVB6o+LZYJ9ipXXc+JDXNyqhCO84fOWaH2CpT/wr4QMUe8wem ryE/QEqeWUPNrCKvnGMbSSko3mXBcv5gzu8+RPgklipMyNFWGysvkPvHuluxkNzUtZ1M JEzVpHJlzaqt2fy6u9fvzcQO0FzaX9u4dGrEshmbDtwpkEtmOFyeNCEsKSpc9/C2qW56 +iWbLRKNfxw5FjD2EBKG/6NbT6ICCl9oecXmNqH3X7X3NJZSTzTnTFsQCCkc6Y6W9Lyc 3Nxg== X-Forwarded-Encrypted: i=1; AJvYcCWbHc7CEdBdqtl0TIkt36jAayacVj+N7MTRC9yIeAgQc9thtMyknP6JtZ95RGJ+au8CJtCUV5Zgg0WQ0HFK56ON4lX0JBVej/pTAOZ5 X-Gm-Message-State: AOJu0YzmEvU3UqDgF3TzUUCGYnznUHB4LhOBK2T8A2Qe83ohHquTZVYH n6/59alQpYbvRS2q22Dph8QxAtzbOQq06F4bZ+w91zha4eDTxsqpHVSDXZ3o8JtnSr5Zx3SnGN/ MeQ2BIv89FreHOyCoLTpB7Pa5lssfoSiNb25h X-Received: by 2002:a1f:6281:0:b0:4bd:8926:8e15 with SMTP id w123-20020a1f6281000000b004bd89268e15mr747476vkb.0.1707515099445; Fri, 09 Feb 2024 13:44:59 -0800 (PST) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 References: <20240208234539.19113-1-osalvador@suse.de> <20240208234539.19113-3-osalvador@suse.de> In-Reply-To: From: Marco Elver Date: Fri, 9 Feb 2024 22:44:23 +0100 Message-ID: Subject: Re: [PATCH v7 2/4] mm,page_owner: Implement the tracking of the stacks count To: Oscar Salvador Cc: Andrew Morton , linux-kernel@vger.kernel.org, linux-mm@kvack.org, Michal Hocko , Vlastimil Babka , Andrey Konovalov , Alexander Potapenko Content-Type: text/plain; charset="UTF-8" On Fri, 9 Feb 2024 at 22:42, Marco Elver wrote: > > On Fri, 9 Feb 2024 at 22:37, Oscar Salvador wrote: > > > > On Fri, Feb 09, 2024 at 08:45:00AM +0100, Marco Elver wrote: > > > > +/** > > > > + * stack_depo_get_stack - Get a pointer to a stack struct > > > > > > Typo: "depo" -> depot > > > > > > I would also write "stack_record struct", because "stack struct" does not exist. > > > > Fixed. > > > > > > + * @handle: Stack depot handle > > > > + * > > > > + * Return: Returns a pointer to a stack struct > > > > + */ > > > > +struct stack_record *stack_depot_get_stack(depot_stack_handle_t handle); > > > > > > I don't know what other usecases there are for this, but I'd want to > > > make make sure we give users a big hint to avoid unnecessary uses of > > > this function. > > > > > > Perhaps we also want to mark it as somewhat internal, e.g. by > > > prefixing it with __. So I'd call it __stack_depot_get_stack_record(). > > > > Yes, I went with __stack_depot_get_stack_record(), and I updated its doc > > in stackdepot.h, mentioning that is only for internal purposes. > > > > > > +static void inc_stack_record_count(depot_stack_handle_t handle) > > > > +{ > > > > + struct stack_record *stack = stack_depot_get_stack(handle); > > > > + > > > > + if (stack) > > > > + refcount_inc(&stack->count); > > > > +} > > > > > > In the latest stackdepot version in -next, the count is initialized to > > > REFCOUNT_SATURATED to warn if a non-refcounted entry is suddenly used > > > as a refcounted one. In your case this is intentional and there is no > > > risk that the entry will be evicted, so that's ok. But you need to set > > > the refcount to 1 somewhere here on the initial stack_depot_save(). > > > > Well, I went with something like: > > > > static void inc_stack_record_count(depot_stack_handle_t handle) > > { > > struct stack_record *stack = __stack_depot_get_stack_record(handle); > > > > if (stack) { > > /* > > * New stack_records that do not use STACK_DEPOT_FLAG_GET start > > * with REFCOUNT_SATURATED to catch spurious increments of their > > * refcount. > > * Since we do not use STACK_DEPOT_FLAG_{GET,PUT} API, let us > > There is no FLAG_PUT, only stack_depot_put(). Saying you do not use > the refcount to free any entries should hopefully make it clear that > even if the refcount saturates and you wrap around to 1, nothing > catastrophic will happen. > > > * set a refcount of 1 ourselves. > > */ > > if (refcount_read(&stack->count) == REFCOUNT_SATURATED) > > refcount_set(&stack->count, 1); Do you need to inc the first allocation? Should there be an "else" here instead of always doing refcount_inc()? > > refcount_inc(&stack->count); > > } > > } > > That looks reasonable.