Received: by 2002:a05:6358:1087:b0:cb:c9d3:cd90 with SMTP id j7csp678009rwi; Thu, 13 Oct 2022 03:53:41 -0700 (PDT) X-Google-Smtp-Source: AMsMyM6ZdzlZ7fg8mxAG9LXUpmvM30aYvu1feQy59F3SCawJosf+cky556EqFeYaGLqFI2ERkc7S X-Received: by 2002:a05:6402:514e:b0:458:7e08:bbc1 with SMTP id n14-20020a056402514e00b004587e08bbc1mr30670123edd.112.1665658421152; Thu, 13 Oct 2022 03:53:41 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1665658421; cv=none; d=google.com; s=arc-20160816; b=kyZgANMBtS+93bssC76gyWWydMuzpV3svKOk58SBytKVwFQxpopGw7fq//Z5Il9O0w g2m3/6fU8yo1RJG1tXjX1O7sjA76RzgqiW132IFml2X2X7XltpkZvzc54cQNW7ntoAE3 ryP9Q4J84uIDV15rbVd0s8wWhx1ulFCb3IeE5hdigCG2eW9UQpmnWfRe8KYiRo7n5tHf t3VNHmiVPoSGv1Cgn7I9tlVr+EZjqkBfDZ0tsk7uxEPjdIbWz8gxdLGXg0P2thpXGm3Y ng6nCp8l0ic7Un2DHLpz/yGbbEYThVMm+Lqag9TVjB/rcqMVLq9Ihy50L1G4y3jVkd43 /6fw== 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:subject:user-agent:mime-version:date:message-id :dkim-signature; bh=zY1ojGxBpTi2hn+yoQwCvHy/W57pGU8ECyExV1y6qnQ=; b=maKE8TQnpOVgedXkRQnts8sDAyLbtoWIbNSB+6/HKo82IoKlF6HA/SifX8OwxRtJNq 6Q/Xj9hruQTJ84kklFUnf+f98gNd7pjeZbw2b5O+uF74bW2K3VauWbx2/O8IAfW1QZKG CmVifDFIOnGx7eoAqPT8VjPQF0QyJxqLxNGS9If7oqFbJTWVQx8rKHj4tRO6R3fKfcjj qgEunet26uH+z/7Xb8S7iN9av7kzAdhirZ3M1nKKSwA+jVMAaQQsnkPd6QjN6A1KeRmc vwXKqJziYJmwE4QTqyhSVOwTY5YA0NSrSWbw7OnAsIsaiezY2WeOtfsRmLRbTvb1oK1t 83Rw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@bytedance-com.20210112.gappssmtp.com header.s=20210112 header.b=1DWlgqus; 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=fail (p=NONE sp=NONE dis=NONE) header.from=bytedance.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id gs37-20020a1709072d2500b0078dd22dd569si8589111ejc.121.2022.10.13.03.53.14; Thu, 13 Oct 2022 03:53:41 -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=@bytedance-com.20210112.gappssmtp.com header.s=20210112 header.b=1DWlgqus; 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=fail (p=NONE sp=NONE dis=NONE) header.from=bytedance.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229590AbiJMKpK (ORCPT + 99 others); Thu, 13 Oct 2022 06:45:10 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59234 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229599AbiJMKpH (ORCPT ); Thu, 13 Oct 2022 06:45:07 -0400 Received: from mail-pf1-x435.google.com (mail-pf1-x435.google.com [IPv6:2607:f8b0:4864:20::435]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DBFA237FAF for ; Thu, 13 Oct 2022 03:45:03 -0700 (PDT) Received: by mail-pf1-x435.google.com with SMTP id g28so1577028pfk.8 for ; Thu, 13 Oct 2022 03:45:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance-com.20210112.gappssmtp.com; s=20210112; h=content-transfer-encoding:in-reply-to:from:references:cc:to:subject :user-agent:mime-version:date:message-id:from:to:cc:subject:date :message-id:reply-to; bh=zY1ojGxBpTi2hn+yoQwCvHy/W57pGU8ECyExV1y6qnQ=; b=1DWlgqusN67Nh/Lk0vXcd5QO3A5QObZkpdbC+9nCPpKZvveDt4EyVeNBhRLQ23AlXd 977ei/TEQ5w04x8QFrh9vK85nWyFHYCPiEaolBsaz7GeG7QFBSaY+dlNOHno6oOf32ts 4N1sMJ5aaflczzA2acYDlJXdK3LkQbBYEiT9SORWT0jpyBLLwva+RLXppJFiA7cwOt1D xF/2Da+GoVl5CgdIHolQooeSsPun+ic5B1zrsYTlZLUun6fZZ6e/8p258fvfSQXeo8Fi xapBep1B08oRiNU2KOTkkNovTrOeQUwNX8jUj6gAAp91QgWBOTQoKESwmKTfpuiawofo inGg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:in-reply-to:from:references:cc:to:subject :user-agent:mime-version:date:message-id:x-gm-message-state:from:to :cc:subject:date:message-id:reply-to; bh=zY1ojGxBpTi2hn+yoQwCvHy/W57pGU8ECyExV1y6qnQ=; b=ON5Cyjpq08Hb6thnaKTRavuFzBtbe/tuHRbOaPG8iHY0QFGep8eOypgRYrQQzY/l/r FJiZGqh9jKYtLT6Gcfln4NHi9ZzfelgIYyjtfGlrKNtS3UaKtLJJyU09lBypFfD2bmiv gn5LBcZSOvuE0H++lz6Aen2Zeqe+HxqnxQLtSmphz7AwlBTx216H8jED9Mvl37Xyd0e8 bKTZea5wDgF/O9htu+qFZ2dzjDXCL6+d2LUqXFXHKw0BM3kkOWfE3u11Pxctm3cA3ICJ YidokHRWVN2AQ4RrniR9Q7TEOZiSjfGsXHOSpQtFJdr+ZYjD9hYxigpV89u6ULMPP9wZ acFg== X-Gm-Message-State: ACrzQf1z+yA7VFANfhl8cr70WU78o204JYXKV2r/sPDvlvcmI0Fwggb1 W26RxOrCrKoKPIplzBi7Hk4YlVXLCJGU8g== X-Received: by 2002:a05:6a00:23d2:b0:565:84d7:64c3 with SMTP id g18-20020a056a0023d200b0056584d764c3mr11206898pfc.20.1665657902431; Thu, 13 Oct 2022 03:45:02 -0700 (PDT) Received: from [10.68.76.92] ([139.177.225.245]) by smtp.gmail.com with ESMTPSA id r1-20020aa79ec1000000b00538056de6ecsm1687688pfq.52.2022.10.13.03.44.58 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 13 Oct 2022 03:45:01 -0700 (PDT) Message-ID: Date: Thu, 13 Oct 2022 18:44:55 +0800 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:102.0) Gecko/20100101 Thunderbird/102.3.2 Subject: Re: [External] Re: [RFC] mm: add new syscall pidfd_set_mempolicy() To: Michal Hocko Cc: corbet@lwn.net, akpm@linux-foundation.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, linux-api@vger.kernel.org, linux-doc@vger.kernel.org, wuyun.abel@bytedance.com References: <20221010094842.4123037-1-hezhongkun.hzk@bytedance.com> <582cf257-bc0d-c96e-e72e-9164cff4fce1@bytedance.com> From: Zhongkun He In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-3.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,NICE_REPLY_A,RCVD_IN_DNSWL_NONE,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 12-10-22 19:22:21, Zhongkun He wrote: >>> >>> Yes, this will require some refactoring and one potential way is to make >>> mpol ref counting unconditional. The conditional ref. counting has >>> already caused issues in the past and the code is rather hard to follow >>> anyway. I am not really sure this optimization is worth it. >>> >>> Another option would be to block the pidfd side of things on completion >>> which would wake it up from the task_work context but I would rather >>> explore the ref counting approach first and only if this is proven to be >>> too expensive to go with hacks like this. >> >> Hi Michal >> >> The counting approach means executing mpol_get/put() when start/finish using >> mempolicy,right? > > We already do that via mpol_{get,put} but there are cases where the > reference counting is ignored because it cannot be freed and also mpol_cond_put > resp. open coded versions of mpol_needs_cond_ref. Hi Michal Could we try to change the MPOL_F_SHARED flag to MPOL_F_STATIC to mark static mempolicy which cannot be freed, and mpol_needs_cond_ref can use MPOL_F_STATIC to avoid freeing the static mempolicy. MPOL_F_SHARED loses its original meaning in counting approach. Thanks.