Received: by 2002:a05:6a10:7420:0:0:0:0 with SMTP id hk32csp602853pxb; Tue, 15 Feb 2022 23:28:00 -0800 (PST) X-Google-Smtp-Source: ABdhPJwfYrgxSupx0PIGPSvJafTRS7vGXQrsAS39MImLlb9SxU9CT331/K/M3nmVGhARYn5Dr5ib X-Received: by 2002:a17:902:a9c3:b0:14d:c5cc:d26c with SMTP id b3-20020a170902a9c300b0014dc5ccd26cmr1669768plr.18.1644996480274; Tue, 15 Feb 2022 23:28:00 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1644996480; cv=none; d=google.com; s=arc-20160816; b=xKvFqhPgbDWopHslmqcHYLvCtLhwI7gLVqAcIBFWSeXuSVHIVevYpf+wGMBQtvIvpQ PMERkkYcYntjdkK9nCEI6OZpCoUy+SeAuZnF7ZnB2zOOVrWbHPCZQ1LwijRdudPRahiw i2AagFNVjKhNoKdyKNY1y1fbf+2s8uw2yR44yFPM+pxGk5DZG4Ewiate1Zr1WjWQRzrJ LIaUcnCkU2RRSa17PW64Q8JO1b5IDs6JvFSYItP65sqSqpVLpSMsvYNZepzO3uS0RgA4 qnNWp7q/oEEtBOZuQa5ZLA7g7J/5PkwQX5QoMZYA1PG15XlhpoppB+auoBHP158sKuwS TLRA== 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=+Xnr8BvsNvJcUeAT+XTUM3XKtkq81lQw2/bkBVhK17c=; b=oQm4XZvKQb3bgleCCyfNlwjIje5wZc9Gs2hSfqVEPTga3VDPGT/etjf/fZuGVSd86d ZdnSnGtFLOaH7D4ni45Wze9Tub9vCF3lY9NWEL58JKRyS/A/K5GSEhPfia4zphzeI42p kfyGd0sXmpADuX/dHs16FOru79t35rBsu3MQP35iUi1secc4BuJR4oZxgxf3TSZJcuvx ZvMuw7Ybdix/lnIGg80IEH836wlU0st+LG/zxEkgRtxYAmy6+ZjgDLjVtx3TnXi2O99g 3RkGzCu20GMAd80satlCzhYVr/DxuDi1iMxQv7UeHKdPAxUPuv4x8b6E+mgBSy+9Tk/n zciA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b="Sfe/kuKE"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id y15si773396pfa.204.2022.02.15.23.27.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 15 Feb 2022 23:28:00 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) client-ip=2620:137:e000::1:18; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b="Sfe/kuKE"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id A02C11C884A; Tue, 15 Feb 2022 22:55:56 -0800 (PST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241666AbiBOSu2 (ORCPT + 99 others); Tue, 15 Feb 2022 13:50:28 -0500 Received: from mxb-00190b01.gslb.pphosted.com ([23.128.96.19]:45394 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233448AbiBOSu0 (ORCPT ); Tue, 15 Feb 2022 13:50:26 -0500 Received: from mail-lf1-x133.google.com (mail-lf1-x133.google.com [IPv6:2a00:1450:4864:20::133]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 36D7D74850 for ; Tue, 15 Feb 2022 10:50:16 -0800 (PST) Received: by mail-lf1-x133.google.com with SMTP id u20so10124784lff.2 for ; Tue, 15 Feb 2022 10:50:16 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=+Xnr8BvsNvJcUeAT+XTUM3XKtkq81lQw2/bkBVhK17c=; b=Sfe/kuKEpWEWZjVJDL2psXjG9oUfvqPlmdtCHVjzjva5Wf4hgOym+ssmVRUnZneaA2 rEkXJ6PqgGUbzerluit/C1Y3RqEu1S5bYN/tNFSYc4A5kPeu9G3E82vvyMHH6f16rRsY y+OdypvtdIdQcjShE2Ydr+tNu8kR1mF0qx5XOsBDCXMb09E2+SV+WVbERkryp01EqPei 0+5L0KO/aEa5PsYc4A+s/3lgkQDYrL7LcIUbxKDZxMJD+qr4LQbpfxisHlC99/g6Rd7E qvdfK8AZjD7qDatwPsLGEWXQtAWkFS+YwYoq/b26HhsMtTgjy6v3qudX31TKl19Ek6Fi fetw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=+Xnr8BvsNvJcUeAT+XTUM3XKtkq81lQw2/bkBVhK17c=; b=xgFtYKYfjZPYcg9zkey3N1YlkC0wBBDJzNUcI8Qmhxp8RrHzguKDRMq9yX96I9sjlD BCY/alATOiCKNgwS0T7LdHs7X0bsNhOGfzq6I+6YHwG3vjG08V4B3FaJvKudpsGONgOz O1wkF4IJ1Ru1zhLrd7tnE6cxLuo5M7EarN3imhGie69BT2E0Q3qrVFllwyaKNIrBuQA7 wEUF4Z467ygrlCSnSOZnhVLXriV+gAqm9RhJ8fZfDbhLYk+oWTsF32ucg70t2tmpO7mx iRKSq1Z+dGBdxfy4Yjtcwhl8xUuizvZNgTbkXfgmXjaBV+BV4NY6Hy8HXoUaByaBaAqy 2fnw== X-Gm-Message-State: AOAM530cyEOmcM5Ckyaa8Uwaf+1E1O2otXvDKcxWrqW8JrdeoVNykMKo MRmHhOZ5nOlKL9REk3PtscAbt+k1tYAqoq5F2GZ6Fg== X-Received: by 2002:a05:6512:10ce:: with SMTP id k14mr328361lfg.210.1644951014338; Tue, 15 Feb 2022 10:50:14 -0800 (PST) MIME-Version: 1.0 References: <20220211064917.2028469-1-shakeelb@google.com> <20220211064917.2028469-5-shakeelb@google.com> In-Reply-To: <20220211064917.2028469-5-shakeelb@google.com> From: Shakeel Butt Date: Tue, 15 Feb 2022 10:50:03 -0800 Message-ID: Subject: Re: [PATCH v2 4/4] memcg: synchronously enforce memory.high for large overcharges To: Johannes Weiner , Michal Hocko , Roman Gushchin Cc: Chris Down , Andrew Morton , Cgroups , Linux MM , LKML Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-9.5 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RDNS_NONE,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE, USER_IN_DEF_DKIM_WL autolearn=no 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, Feb 10, 2022 at 10:49 PM Shakeel Butt wrote: > > The high limit is used to throttle the workload without invoking the > oom-killer. Recently we tried to use the high limit to right size our > internal workloads. More specifically dynamically adjusting the limits > of the workload without letting the workload get oom-killed. However due > to the limitation of the implementation of high limit enforcement, we > observed the mechanism fails for some real workloads. > > The high limit is enforced on return-to-userspace i.e. the kernel let > the usage goes over the limit and when the execution returns to > userspace, the high reclaim is triggered and the process can get > throttled as well. However this mechanism fails for workloads which do > large allocations in a single kernel entry e.g. applications that > mlock() a large chunk of memory in a single syscall. Such applications > bypass the high limit and can trigger the oom-killer. > > To make high limit enforcement more robust, this patch makes the limit > enforcement synchronous only if the accumulated overcharge becomes > larger than MEMCG_CHARGE_BATCH. So, most of the allocations would still > be throttled on the return-to-userspace path but only the extreme > allocations which accumulates large amount of overcharge without > returning to the userspace will be throttled synchronously. The value > MEMCG_CHARGE_BATCH is a bit arbitrary but most of other places in the > memcg codebase uses this constant therefore for now uses the same one. > > Signed-off-by: Shakeel Butt Any comments or concerns on this patch? Otherwise I would ask Andrew to add this series into the mm tree. > --- > Changes since v1: > - Based on Roman's comment simply the sync enforcement and only target > the extreme cases. > > mm/memcontrol.c | 5 +++++ > 1 file changed, 5 insertions(+) > > diff --git a/mm/memcontrol.c b/mm/memcontrol.c > index 292b0b99a2c7..0da4be4798e7 100644 > --- a/mm/memcontrol.c > +++ b/mm/memcontrol.c > @@ -2703,6 +2703,11 @@ static int try_charge_memcg(struct mem_cgroup *memcg, gfp_t gfp_mask, > } > } while ((memcg = parent_mem_cgroup(memcg))); > > + if (current->memcg_nr_pages_over_high > MEMCG_CHARGE_BATCH && > + !(current->flags & PF_MEMALLOC) && > + gfpflags_allow_blocking(gfp_mask)) { > + mem_cgroup_handle_over_high(); > + } > return 0; > } > > -- > 2.35.1.265.g69c8d7142f-goog >