Received: by 2002:a05:7412:f690:b0:e2:908c:2ebd with SMTP id ej16csp802733rdb; Thu, 19 Oct 2023 22:33:52 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFG+O56h2PXojZPp7zm9WwbIgz1G626feMjn4y7P6yFCpyo0BQKVX+yRzd26g9yixIi7bwz X-Received: by 2002:a05:6a20:8f27:b0:153:63b9:8bf9 with SMTP id b39-20020a056a208f2700b0015363b98bf9mr1171961pzk.0.1697780032536; Thu, 19 Oct 2023 22:33:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1697780032; cv=none; d=google.com; s=arc-20160816; b=qp9iseSDlx7QhTY58Xt0/MSfGW+tM0wh9jNmLlQZVsfgc7x7uZdABLeiHOh4wRJZA4 EBZwxhnQj5l/MHB0HqggPNZMcf34K1iqZFBYezok87GV5aT3yrvuLUlpQkWqq7SnlOyp MuMMQo4esFiRbq231kQJyeKUDE3teXFAzi8mmT5T2lN5+RUrlWTzlgeh+tnV/HPb0nfF jPjqHrNw2X9qdVQ7mswATBFf6tm8vzXWlHTyxvs4Byg3qFYuqkh1wu7C31S12QZuZjIa PDRX8tkV6cXitxPOUBWLURXG+a0NpeTzFfmzdzBWtxEuQlV8Lqbx4gi9j5L18UePjQMn wlVA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to:from :references:cc:to:content-language:subject:user-agent:mime-version :date:message-id:dkim-signature:dkim-signature; bh=PyJ/wzDi6i48iVYJkqxkfxMlKHMIM7+DIbHS1YWntQA=; fh=bhn5GrsKQehzVS/dlUb/OICttgMAyeLnksQMeyfX/Hk=; b=StKEstJVSlcxF8kFFMiGkdtcuZx5GgNNBkyNQ3sk65o2FgQx2trjlyyYOMFwQpwcpD 3YxO7eayRWENTUWiy3Qs2JX0mXYzcpZ5Qy23XWtyb6QQZhaPVvGQzEKhl5kGf84UBlx1 bJKjJxMCOZTJu9+x3iLj8wEc71FZGHoMVWdLfeOUkwsDB+tfSIqy6jYKk4qLpN/bJA/H +smU8mBOquQaLTMkevOPeJor57b5lk8ykbCtvrxYEXkN5+XwAZKcZuizHCk8B3ejMJoT JC81gYt3G2hEsGkES/4jLx1do7HmnIIN4gra71wZCcJCYtuqj47ObBf/hXjk/T0du7PI Eihw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@suse.cz header.s=susede2_rsa header.b=FcD3e3il; dkim=neutral (no key) header.i=@suse.cz header.s=susede2_ed25519 header.b=5h+O0a0I; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from agentk.vger.email (agentk.vger.email. [2620:137:e000::3:2]) by mx.google.com with ESMTPS id l13-20020a170903120d00b001c9af5305dasi1129126plh.126.2023.10.19.22.33.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 19 Oct 2023 22:33:52 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 as permitted sender) client-ip=2620:137:e000::3:2; Authentication-Results: mx.google.com; dkim=pass header.i=@suse.cz header.s=susede2_rsa header.b=FcD3e3il; dkim=neutral (no key) header.i=@suse.cz header.s=susede2_ed25519 header.b=5h+O0a0I; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by agentk.vger.email (Postfix) with ESMTP id 545DC81EA70C; Thu, 19 Oct 2023 22:33:50 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at agentk.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233516AbjJTFdj (ORCPT + 99 others); Fri, 20 Oct 2023 01:33:39 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58692 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233471AbjJTFdi (ORCPT ); Fri, 20 Oct 2023 01:33:38 -0400 Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.220.28]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8836A119; Thu, 19 Oct 2023 22:33:36 -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-out1.suse.de (Postfix) with ESMTPS id 0F50D21842; Fri, 20 Oct 2023 05:33:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_rsa; t=1697780014; 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=PyJ/wzDi6i48iVYJkqxkfxMlKHMIM7+DIbHS1YWntQA=; b=FcD3e3il7pO1iMz9Uisi8xhSglA1naMreeVOep+yyOgCE/cf3RW/9ahNz8F0dtYmx+r1op yip2TC0SZ/Ep0ogz/M89H9TFl7c6AYi2ktfhT3zqRdbwdnuC4iJXp01YPrVrsoT2rChRjG ARk0mCYhxOJYhcuhuvOmWO3KMJiJxEc= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_ed25519; t=1697780014; 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=PyJ/wzDi6i48iVYJkqxkfxMlKHMIM7+DIbHS1YWntQA=; b=5h+O0a0IBCPO5f430xj/w4BMFK+OzoLtiycyRI5cZLMXlr0zhMNftsRBGLuaPXFzEbEREi m5h9XE6FmFS7rwBA== 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 DB1021348D; Fri, 20 Oct 2023 05:33:33 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id VufKNC0RMmXyXgAAMHmgww (envelope-from ); Fri, 20 Oct 2023 05:33:33 +0000 Message-ID: <69ad0c7c-9e34-9eb6-835d-ac40a5023d91@suse.cz> Date: Fri, 20 Oct 2023 07:33:33 +0200 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.15.1 Subject: Re: [PATCH v5 2/6] mm: kmem: add direct objcg pointer to task_struct Content-Language: en-US To: Roman Gushchin , Andrew Morton Cc: linux-kernel@vger.kernel.org, cgroups@vger.kernel.org, Johannes Weiner , Michal Hocko , Shakeel Butt , Muchun Song , Dennis Zhou , David Rientjes , Naresh Kamboju References: <20231019225346.1822282-1-roman.gushchin@linux.dev> <20231019225346.1822282-3-roman.gushchin@linux.dev> From: Vlastimil Babka In-Reply-To: <20231019225346.1822282-3-roman.gushchin@linux.dev> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit Authentication-Results: smtp-out1.suse.de; none X-Spam-Level: X-Spam-Score: -8.26 X-Spamd-Result: default: False [-8.26 / 50.00]; ARC_NA(0.00)[]; RCVD_VIA_SMTP_AUTH(0.00)[]; BAYES_HAM(-0.16)[69.18%]; FROM_HAS_DN(0.00)[]; TO_DN_SOME(0.00)[]; TO_MATCH_ENVRCPT_ALL(0.00)[]; NEURAL_HAM_LONG(-3.00)[-1.000]; MIME_GOOD(-0.10)[text/plain]; REPLY(-4.00)[]; DKIM_SIGNED(0.00)[suse.cz:s=susede2_rsa,suse.cz:s=susede2_ed25519]; NEURAL_HAM_SHORT(-1.00)[-1.000]; RCPT_COUNT_SEVEN(0.00)[11]; FROM_EQ_ENVFROM(0.00)[]; MIME_TRACE(0.00)[0:+]; RCVD_COUNT_TWO(0.00)[2]; RCVD_TLS_ALL(0.00)[]; MID_RHS_MATCH_FROM(0.00)[] X-Spam-Status: No, score=-4.2 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, NICE_REPLY_A,SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on agentk.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (agentk.vger.email [0.0.0.0]); Thu, 19 Oct 2023 22:33:50 -0700 (PDT) On 10/20/23 00:53, Roman Gushchin wrote: > To charge a freshly allocated kernel object to a memory cgroup, the > kernel needs to obtain an objcg pointer. Currently it does it > indirectly by obtaining the memcg pointer first and then calling to > __get_obj_cgroup_from_memcg(). > > Usually tasks spend their entire life belonging to the same object > cgroup. So it makes sense to save the objcg pointer on task_struct > directly, so it can be obtained faster. It requires some work on fork, > exit and cgroup migrate paths, but these paths are way colder. > > To avoid any costly synchronization the following rules are applied: > 1) A task sets it's objcg pointer itself. > > 2) If a task is being migrated to another cgroup, the least > significant bit of the objcg pointer is set atomically. > > 3) On the allocation path the objcg pointer is obtained locklessly > using the READ_ONCE() macro and the least significant bit is > checked. If it's set, the following procedure is used to update > it locklessly: > - task->objcg is zeroed using cmpxcg > - new objcg pointer is obtained > - task->objcg is updated using try_cmpxchg > - operation is repeated if try_cmpxcg fails > It guarantees that no updates will be lost if task migration > is racing against objcg pointer update. It also allows to keep > both read and write paths fully lockless. > > Because the task is keeping a reference to the objcg, it can't go away > while the task is alive. > > This commit doesn't change the way the remote memcg charging works. > > Signed-off-by: Roman Gushchin (Cruise) > Tested-by: Naresh Kamboju > Acked-by: Johannes Weiner > Acked-by: Shakeel Butt Reviewed-by: Vlastimil Babka