Received: by 2002:a05:6358:d09b:b0:dc:cd0c:909e with SMTP id jc27csp776244rwb; Wed, 16 Nov 2022 07:32:08 -0800 (PST) X-Google-Smtp-Source: AA0mqf5FHi82kziGV2gJGr+2O6WD5ZWbHtWtjyWEKU5skpyyERky2UCRKwKp/CXZ4rOgMwT9ca6w X-Received: by 2002:a63:5f8c:0:b0:476:f92f:885b with SMTP id t134-20020a635f8c000000b00476f92f885bmr797580pgb.31.1668612728147; Wed, 16 Nov 2022 07:32:08 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1668612728; cv=none; d=google.com; s=arc-20160816; b=mucDWDBjTQwLDoavmIEb2TDSHicvFCCGH93wMMt9JMDziF6OPUHFzEYqxUsGsjeCQn WLyO11xSxNRUV/qPgwh/QcfD4nPWUqHA4ZpTMHj2OEODCe2ozBFiln4zQsq/90CGSshj qLWgpAVyDi8XwXujLLT9z0XxMYXe+YI1nhvGW+WiRhle82eMlBsxcKLO+1X2t67I/3vx hHID0+XKikinyTYp0c5ZbHGkMyAHHmafgSxhQyYbyRUDqsIbRpIzl7KU1R2HRphTgfbS +JHti2tHVCBVRg1z3gaYEs3Iwn471GUWwJkNCUM3gtF06A3BsDiS2IClHcQB395hPzk9 e2hA== 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; bh=3vl4NdpO4irC1eRJoV821C0JFp7+4A15d5hSm1FQvTo=; b=GSZRRzsYCJVOKPuuzS0aIeFBQpmkC004LcpJyHdkR04Huu5rOcZaIRSRSH99ZWWk4t DtaL2MLWyq0Nnn20oiy8Gjpx76FZ2kmFeDg6DJVwcJGhM4FIVYPO8kX7ZXsHm5IBps5f 88nF76z5rOQF//tEsq7iIvudr9vo405fDB8HbpUqcv/00dtP8WGfxBC4ZQipXptJ2oOI J/hU97e6kIdBJ38xoMkn9qCwLVDaNrdrJg3jSHkq/qg8/qSXWW3NpRpm6EX3oTMMDUma IOwS7f7paFhmOS8FzQLBM08+EwrdX/HzwHyFNv9FRxtHVUKqxslzQWcIdd0iZh85cZCY VaQw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@suse.com header.s=susede1 header.b=eqaB6EP2; 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=QUARANTINE sp=QUARANTINE dis=NONE) header.from=suse.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id t194-20020a635fcb000000b00476879d7d6esi7515914pgb.576.2022.11.16.07.31.56; Wed, 16 Nov 2022 07:32:08 -0800 (PST) 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.com header.s=susede1 header.b=eqaB6EP2; 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=QUARANTINE sp=QUARANTINE dis=NONE) header.from=suse.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234326AbiKPO5g (ORCPT + 91 others); Wed, 16 Nov 2022 09:57:36 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48704 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233632AbiKPO5R (ORCPT ); Wed, 16 Nov 2022 09:57:17 -0500 Received: from smtp-out2.suse.de (smtp-out2.suse.de [IPv6:2001:67c:2178:6::1d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 138DCFADF; Wed, 16 Nov 2022 06:57:16 -0800 (PST) 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 98D361F94F; Wed, 16 Nov 2022 14:57:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1668610635; 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=3vl4NdpO4irC1eRJoV821C0JFp7+4A15d5hSm1FQvTo=; b=eqaB6EP2GKiw5QP6JiW0cWOM1NG4anZRyh1calWKdEwUX95RbEKck+SxlKqWruwGYlnjRW InAsn8C+8XCSZZ23Mcg3b7PsV6E7utY9JOJX4lXDMQlPNUCOIwlxjZtQp2QRMW+DkxU1bQ lzj7mbU+Msd0KWWV5/hZ7unfoL4q6B4= 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 7A24113480; Wed, 16 Nov 2022 14:57:15 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id qwJoG0v6dGOYYgAAMHmgww (envelope-from ); Wed, 16 Nov 2022 14:57:15 +0000 Date: Wed, 16 Nov 2022 15:57:14 +0100 From: Michal Hocko To: Zhongkun He Cc: Andrew Morton , corbet@lwn.net, linux-mm@kvack.org, linux-kernel@vger.kernel.org, linux-api@vger.kernel.org, linux-doc@vger.kernel.org Subject: Re: [External] Re: [PATCH v2] mm: add new syscall pidfd_set_mempolicy(). Message-ID: References: <20221111084051.2121029-1-hezhongkun.hzk@bytedance.com> <20221111112732.30e1696bcd0d5b711c188a9a@linux-foundation.org> <3a3b4f5b-14d1-27d8-7727-cf23da90988f@bytedance.com> <82c9c89c-aee2-08a3-e562-359631bb0137@bytedance.com> <0bd0b744-3d97-b4c3-a4fb-6040f8f8024a@bytedance.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <0bd0b744-3d97-b4c3-a4fb-6040f8f8024a@bytedance.com> 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 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 Wed 16-11-22 19:28:10, Zhongkun He wrote: > Hi Michal, I've done the performance testing, please check it out. > > > > Yes this is all understood but the level of the overhead is not really > > > clear. So the question is whether this will induce a visible overhead. > > > Because from the maintainability point of view it is much less costly to > > > have a clear life time model. Right now we have a mix of reference > > > counting and per-task requirements which is rather subtle and easy to > > > get wrong. In an ideal world we would have get_vma_policy always > > > returning a reference counted policy or NULL. If we really need to > > > optimize for cache line bouncing we can go with per cpu reference > > > counters (something that was not available at the time the mempolicy > > > code has been introduced). > > > > > > So I am not saying that the task_work based solution is not possible I > > > just think that this looks like a good opportunity to get from the > > > existing subtle model. > > Test tools: > numactl -m 0-3 ./run-mmtests.sh -n -c configs/config-workload- > aim9-pagealloc test_name > > Modification: > Get_vma_policy(), get_task_policy() always returning a reference > counted policy, except for the static policy(default_policy and > preferred_node_policy[nid]). It would be better to add the patch that has been tested. > All vma manipulation is protected by a down_read, so mpol_get() > can be called directly to take a refcount on the mpol. but there > is no lock in task->mempolicy context. > so task->mempolicy should be protected by task_lock. > > struct mempolicy *get_task_policy(struct task_struct *p) > { > struct mempolicy *pol; > int node; > > if (p->mempolicy) { > task_lock(p); > pol = p->mempolicy; > mpol_get(pol); > task_unlock(p); > if (pol) > return pol; > } One way to deal with that would be to use a similar model as css_tryget Btw. have you tried to profile those slowdowns to identify hotspots? Thanks -- Michal Hocko SUSE Labs