Received: by 2002:a05:6358:1087:b0:cb:c9d3:cd90 with SMTP id j7csp2742455rwi; Fri, 28 Oct 2022 10:37:02 -0700 (PDT) X-Google-Smtp-Source: AMsMyM4oDWOC9wbWlaKfx5TvUFM//cHwF1d1MWkVH2y5PAk/I05aijlRxTWTO8hoyYGAfDGYRHBY X-Received: by 2002:a17:907:724c:b0:7ad:8f76:1fb8 with SMTP id ds12-20020a170907724c00b007ad8f761fb8mr430301ejc.582.1666978622042; Fri, 28 Oct 2022 10:37:02 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666978622; cv=none; d=google.com; s=arc-20160816; b=pwTD/BGUZG/QybF31R8I5flfufZBoIXbJyr+kLL7s2btjqrESonskhyHPXT1ZF6rhP niSlZHN077smpRpAEg2lTMtd85qyz331HUXUziENf1nNdMnudoYkRZaM7E2bk9ngGz2l NmtIM2H50sdxpwt1Rum+u9RMHDKp3PApe/VRNNcA+YJQmWAWn179i2vdXSMDAG3sUprx KTIPbg7ZBC6PcA4udItwDggee8ANTLj0KmvWXf7y7feD5hFzwxKrQPQsDFtuzM0sCEZ2 VQecB3t1A21JEkk4Q6ZFqpwBxwkrToTsY1ADr7ZMHw1qmRB52Poh/lugBprTLzhVVQUi afWg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=uWRk2+cg4JD0YlEG67ex3jOV5izVRgHvNcMy0hsBnco=; b=EuZQ/ngF9QBkqe+y2rGrKa6bT1eKnyqiwuda9lLS9nhuovcB09HYzOeIadjaf7hXat dYPPOsAXrXqxjhf9PLGKtJciExwYjGJInc7iLubcj+1RJzv4YC75mYvl6INna0m736wp +G7dvdn1DSYmbJved+XowyXGEpa3Qjglb3KozpLDAKwBpfcNOfurf98X+b7fL01XH6Wy ylZoaic+Tm5xgrHWd49TDpgOhl54cI5iMyezhgwGCQTao3DKNgiAQs+aiP7UCN19bi9c 9w2fcRgzJtKZQ2VZb1OqSERwN/9HRDfEknu54rDQV8sO1jYus6xbf2ciTuYA1bJpa0Sc zkyQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=prHkLIu5; 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=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id u11-20020aa7d98b000000b00460f0c0c565si1583211eds.197.2022.10.28.10.36.35; Fri, 28 Oct 2022 10:37:02 -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=@gmail.com header.s=20210112 header.b=prHkLIu5; 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=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229634AbiJ1RYI (ORCPT + 99 others); Fri, 28 Oct 2022 13:24:08 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45704 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229501AbiJ1RYH (ORCPT ); Fri, 28 Oct 2022 13:24:07 -0400 Received: from mail-pj1-x1035.google.com (mail-pj1-x1035.google.com [IPv6:2607:f8b0:4864:20::1035]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8C02822AB58; Fri, 28 Oct 2022 10:24:06 -0700 (PDT) Received: by mail-pj1-x1035.google.com with SMTP id m14-20020a17090a3f8e00b00212dab39bcdso10501504pjc.0; Fri, 28 Oct 2022 10:24:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=uWRk2+cg4JD0YlEG67ex3jOV5izVRgHvNcMy0hsBnco=; b=prHkLIu5cEuWwbChfnUxhVQzBCXk/zyL6eJyK/Wb7otKwjaCrzIq3XW2UK2JzyS4Iw VO4x7PSyBtEh4QkOXnHq/Lchf8ySh5Aup5b999/W+GXjfDiCBa9zKxEzIVLmyrFfkU6b SxLhNhELaKSgqrlGHWUogD+HSabs65jM9+4kHVbrp6ET9tYi2P7z5K1nXsct2AjsxHF3 vdNFvKJv3dmyRqhBxeOLIIYaE0Av+7Da2kGBtCNqhGpKN+30L8jrC0x8FkOv2RACZ0s3 lp6K36RgYhat5D86/qQ7UbZmmLFIRiHR2RS0D/IBLYMUBqcsEXndnME3dYJ4SMTy+a0i Fh7A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; 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=uWRk2+cg4JD0YlEG67ex3jOV5izVRgHvNcMy0hsBnco=; b=3ALP5fvrmmfa0GyuEkyVfid4qYUSGOLLedSdwQJSn6MW3qa6zhQmcCM4wd7TBVjhKv HZG7R62fLCDWOuprBKsMY6s54LPwT6mGNZBa+6Jb7S5Rc8bnd45s/HKA+AEsS//yOn3z tYLosxivVsRhs6K3gg/miRAwrzlixLY9ITrQC4/ZIVPpmu8PZX1KPamfBBfQgFUbUYK8 DAykpVZwrtrl8rDKcaSvgJkYIc02wdKSdktdfHru9u2nz6EmiNFBWCxGRySrhiNpRGX8 RTsRnUxtbOzXJccaqER4A2FRblCinumAeIJJnf2iNCcnu19FAciVzb3aeu3st8DU1c7y 3tjA== X-Gm-Message-State: ACrzQf2/wYAEHv0qgm8GF+Wq0StGblDq1gtM0w4FhuO8yOLVnQUzIIT0 UourUokuD8QdDak/3gmwcuIFiweyr8EaiDd3zD0= X-Received: by 2002:a17:902:e88a:b0:183:9ecb:ff85 with SMTP id w10-20020a170902e88a00b001839ecbff85mr3434plg.169.1666977846069; Fri, 28 Oct 2022 10:24:06 -0700 (PDT) MIME-Version: 1.0 References: <20221026074343.6517-1-feng.tang@intel.com> <87y1t0ijbk.fsf@yhuang6-desk2.ccr.corp.intel.com> In-Reply-To: <87y1t0ijbk.fsf@yhuang6-desk2.ccr.corp.intel.com> From: Yang Shi Date: Fri, 28 Oct 2022 10:23:53 -0700 Message-ID: Subject: Re: [PATCH] mm/vmscan: respect cpuset policy during page demotion To: "Huang, Ying" Cc: Feng Tang , "Hocko, Michal" , Aneesh Kumar K V , Andrew Morton , Johannes Weiner , Tejun Heo , Zefan Li , Waiman Long , "linux-mm@kvack.org" , "cgroups@vger.kernel.org" , "linux-kernel@vger.kernel.org" , "Hansen, Dave" , "Chen, Tim C" , "Yin, Fengwei" Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-1.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_ENVFROM_END_DIGIT, FREEMAIL_FROM,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 Thu, Oct 27, 2022 at 10:55 PM Huang, Ying wrote: > > Feng Tang writes: > > > On Thu, Oct 27, 2022 at 10:55:58AM -0700, Yang Shi wrote: > >> On Thu, Oct 27, 2022 at 12:12 AM Feng Tang wrote: > >> > > >> > On Thu, Oct 27, 2022 at 01:57:52AM +0800, Yang Shi wrote: > >> > > On Wed, Oct 26, 2022 at 8:59 AM Michal Hocko wrote: > >> > [...] > >> > > > > > This all can get quite expensive so the primary question is, does the > >> > > > > > existing behavior generates any real issues or is this more of an > >> > > > > > correctness exercise? I mean it certainly is not great to demote to an > >> > > > > > incompatible numa node but are there any reasonable configurations when > >> > > > > > the demotion target node is explicitly excluded from memory > >> > > > > > policy/cpuset? > >> > > > > > >> > > > > We haven't got customer report on this, but there are quite some customers > >> > > > > use cpuset to bind some specific memory nodes to a docker (You've helped > >> > > > > us solve a OOM issue in such cases), so I think it's practical to respect > >> > > > > the cpuset semantics as much as we can. > >> > > > > >> > > > Yes, it is definitely better to respect cpusets and all local memory > >> > > > policies. There is no dispute there. The thing is whether this is really > >> > > > worth it. How often would cpusets (or policies in general) go actively > >> > > > against demotion nodes (i.e. exclude those nodes from their allowes node > >> > > > mask)? > >> > > > > >> > > > I can imagine workloads which wouldn't like to get their memory demoted > >> > > > for some reason but wouldn't it be more practical to tell that > >> > > > explicitly (e.g. via prctl) rather than configuring cpusets/memory > >> > > > policies explicitly? > >> > > > > >> > > > > Your concern about the expensive cost makes sense! Some raw ideas are: > >> > > > > * if the shrink_folio_list is called by kswapd, the folios come from > >> > > > > the same per-memcg lruvec, so only one check is enough > >> > > > > * if not from kswapd, like called form madvise or DAMON code, we can > >> > > > > save a memcg cache, and if the next folio's memcg is same as the > >> > > > > cache, we reuse its result. And due to the locality, the real > >> > > > > check is rarely performed. > >> > > > > >> > > > memcg is not the expensive part of the thing. You need to get from page > >> > > > -> all vmas::vm_policy -> mm -> task::mempolicy > >> > > > >> > > Yeah, on the same page with Michal. Figuring out mempolicy from page > >> > > seems quite expensive and the correctness can't be guranteed since the > >> > > mempolicy could be set per-thread and the mm->task depends on > >> > > CONFIG_MEMCG so it doesn't work for !CONFIG_MEMCG. > >> > > >> > Yes, you are right. Our "working" psudo code for mem policy looks like > >> > what Michal mentioned, and it can't work for all cases, but try to > >> > enforce it whenever possible: > >> > > >> > static bool __check_mpol_demotion(struct folio *folio, struct vm_area_struct *vma, > >> > unsigned long addr, void *arg) > >> > { > >> > bool *skip_demotion = arg; > >> > struct mempolicy *mpol; > >> > int nid, dnid; > >> > bool ret = true; > >> > > >> > mpol = __get_vma_policy(vma, addr); > >> > if (!mpol) { > >> > struct task_struct *task; > >> > if (vma->vm_mm) > >> > task = vma->vm_mm->owner; > >> > >> But this task may not be the task you want IIUC. For example, the > >> process has two threads, A and B. They have different mempolicy. The > >> vmscan is trying to demote a page belonging to thread A, but the task > >> may point to thread B, so you actually get the wrong mempolicy IIUC. > > > > Yes, this is a valid concern! We don't have good solution for this. > > For memory policy, we may only handle the per-vma policy for now whose > > cost is relatively low, as a best-effort try. > > Yes. The solution isn't perfect, especially for multiple-thread > processes with thread specific memory policy. But the proposed code > above can support the most common cases at least, that is, run workload > with `numactl`. Not only multi threads, but also may be broken for shared pages. When you do rmap walk, you may get multiple contradict mempolicy, which one would you like to obey? TBH I'm not sure whether such half-baked solution is worth it or not, at least at this moment. The cost is not cheap, but the gain may not be worth it IMHO. > > Best Regards, > Huang, Ying