Received: by 10.213.65.68 with SMTP id h4csp2316081imn; Thu, 5 Apr 2018 12:47:22 -0700 (PDT) X-Google-Smtp-Source: AIpwx48Qfcxy2zo0z/NGGRCu/gbQBjpLM/W+zct4P53W59Qg3WfV4rH0tyayEgJZzTTOn4tbf1v5 X-Received: by 2002:a17:902:6a85:: with SMTP id n5-v6mr24416714plk.313.1522957642161; Thu, 05 Apr 2018 12:47:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1522957642; cv=none; d=google.com; s=arc-20160816; b=J3NqplhPHb1H+oHRDKCQbkY2BEX7O0TmhYRXUA2h02N+/Bi2VfAVMuZK8mXlUnetcg 7l9D/x8xXo6PkFsQITcRgDig3PmzFXSW8i4AXhswcNdBlzJVDaf9th+ETE1CO8P3nN/v ceJVPN/ib5mp2VNo8PAwKUeJXg3Di/fPipdNMswZYSv79RghauaMN6+51VchZIhADPYV egPBQ8w/JxvHWY5us7Sf/wZ/86JiQ3m6QMYzo8EbaULxM6sb7EOi8Me0FF+BV++8IzoT bruFE32iQpJGiGt9Ctacpqwh6ZSXPmP/jMgh6YX7aeqWkaFPZ1cmsjT1m+gq+7AeSOgL a+oQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature:arc-authentication-results; bh=0NfF4vVEsKnmZw0xYoLu3HuKb+m+EfRg8JbBU/Nwa5w=; b=cOvNGi4caO6N37mZFguurc7Q3Ohpmdxg8gF9M8tmudPrwefb5A1vPGayxe0Y0z3t5v yC4BeaYYKDdzH/ZUZoB0+rQIkJ9/9qc3WEDL1d9XEiApEsjHdPKKxBx1wJuXBRi1p0cH 10rNwVpJKMuK+VOHUoqt+VNn/utaEQIpn8JzSn+dUaAkpyxK2PWNPg90b++WSVreCZmH LuvBIFyWZuW5qk3GjkXPzoGAyq/OssPkYIvvjHj/llVHIVseRYMjtbM76OSSbZsD0j5g EFdlrq3uDAk8fAF1fFQOOGRybI2Y6XW/BtcvS8LDQUGIdUDNozRZ1H22jZWwGTzWcMz9 el5g== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@cmpxchg.org header.s=x header.b=0D38xaGO; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=cmpxchg.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id c11-v6si6588312plo.582.2018.04.05.12.47.08; Thu, 05 Apr 2018 12:47:22 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=fail header.i=@cmpxchg.org header.s=x header.b=0D38xaGO; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=cmpxchg.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752940AbeDETpg (ORCPT + 99 others); Thu, 5 Apr 2018 15:45:36 -0400 Received: from gum.cmpxchg.org ([85.214.110.215]:50226 "EHLO gum.cmpxchg.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752552AbeDETpe (ORCPT ); Thu, 5 Apr 2018 15:45:34 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=cmpxchg.org ; s=x; h=In-Reply-To:Content-Type:MIME-Version:References:Message-ID:Subject: Cc:To:From:Date:Sender:Reply-To:Content-Transfer-Encoding:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Id:List-Help:List-Unsubscribe:List-Subscribe: List-Post:List-Owner:List-Archive; bh=0NfF4vVEsKnmZw0xYoLu3HuKb+m+EfRg8JbBU/Nwa5w=; b=0D38xaGOMqxRa2wdKMFEx97HRn XlDkrEh4CCqx9Aexo1GPhBthcA95kzp7xdUxxgiMVofY0P4YJA9sllgFyxJKOjIPefJywlgP70CSR EgPFU2+fprchw5o90Vqv+bkl687I2ORUAzpesmRrt5h2F9kX8PZDCeB5erY1jpAivquI=; Date: Thu, 5 Apr 2018 15:45:26 -0400 From: Johannes Weiner To: Roman Gushchin Cc: linux-mm@kvack.org, Andrew Morton , Michal Hocko , Vladimir Davydov , Tejun Heo , kernel-team@fb.com, cgroups@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH v3 3/4] mm: treat memory.low value inclusive Message-ID: <20180405194526.GC27918@cmpxchg.org> References: <20180405185921.4942-1-guro@fb.com> <20180405185921.4942-3-guro@fb.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20180405185921.4942-3-guro@fb.com> User-Agent: Mutt/1.9.4 (2018-02-28) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Apr 05, 2018 at 07:59:20PM +0100, Roman Gushchin wrote: > If memcg's usage is equal to the memory.low value, avoid reclaiming > from this cgroup while there is a surplus of reclaimable memory. > > This sounds more logical and also matches memory.high and memory.max > behavior: both are inclusive. I was trying to figure out why we did it this way in the first place and found this patch: commit 4e54dede38b45052a941bcf709f7d29f2e18174d Author: Michal Hocko Date: Fri Feb 27 15:51:46 2015 -0800 memcg: fix low limit calculation A memcg is considered low limited even when the current usage is equal to the low limit. This leads to interesting side effects e.g. groups/hierarchies with no memory accounted are considered protected and so the reclaim will emit MEMCG_LOW event when encountering them. Another and much bigger issue was reported by Joonsoo Kim. He has hit a NULL ptr dereference with the legacy cgroup API which even doesn't have low limit exposed. The limit is 0 by default but the initial check fails for memcg with 0 consumption and parent_mem_cgroup() would return NULL if use_hierarchy is 0 and so page_counter_read would try to dereference NULL. I suppose that the current implementation is just an overlook because the documentation in Documentation/cgroups/unified-hierarchy.txt says: "The memory.low boundary on the other hand is a top-down allocated reserve. A cgroup enjoys reclaim protection when it and all its ancestors are below their low boundaries" Fix the usage and the low limit comparision in mem_cgroup_low accordingly. > @@ -5709,7 +5709,7 @@ bool mem_cgroup_low(struct mem_cgroup *root, struct mem_cgroup *memcg) > elow = min(elow, parent_elow * low_usage / siblings_low_usage); > exit: > memcg->memory.elow = elow; > - return usage < elow; > + return usage <= elow; So I think this needs to be usage && usage <= elow to not emit MEMCG_LOW events in case usage == elow == 0.