From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-wr1-f51.google.com (mail-wr1-f51.google.com [209.85.221.51]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A57EA375AB5 for ; Fri, 20 Mar 2026 09:32:44 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.51 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1773999169; cv=none; b=ozSx8QtY2bwc3DsWWU6O2yI2VuhDhThZwRUKko1dOKqkCZwvtG0idmJqdZWLQMvAoVLE6LbARO4kvtiaM5q1CEWJVKeOBBnN41jK3MrcZckGbn6RPf3bSP3LfKLuKf1rCRNbx+L61pqsa3yhU9jHpKQ9Ug5cx5dHEkfP/8YkVTk= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1773999169; c=relaxed/simple; bh=FpNtDIA6oOfc1i8Qt5ngbRNeLYofROBoR5hcrINPuNs=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=dGZbwjCDY3zba2C8qmqUav4Kdbm1htwHlCbCO/sPf/wUOMDGZrg1GeoSA9qrDTZ1EW1nkq1vTD08T7IeK5PRK0M4bE31sV14WzHJIx5Wuh84XhjnP5MWkypLmCcBQKPFsljyAV69vZr3RTDu+IU7O/HRkJY6Pj/IpLdGP0YhEJo= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=suse.com; spf=pass smtp.mailfrom=suse.com; dkim=pass (2048-bit key) header.d=suse.com header.i=@suse.com header.b=SY7DaewO; arc=none smtp.client-ip=209.85.221.51 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=suse.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=suse.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=suse.com header.i=@suse.com header.b="SY7DaewO" Received: by mail-wr1-f51.google.com with SMTP id ffacd0b85a97d-439d8dc4ae4so1348997f8f.2 for ; Fri, 20 Mar 2026 02:32:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=google; t=1773999162; x=1774603962; darn=vger.kernel.org; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=OM7qYlf9HKURWz/+a3T3Y3rxMadnxIAJ8Nie9c0bxzE=; b=SY7DaewOwGJuz8oSJ1n/+tO2+3bE07s0CMA6qOM7klRS4ejIt9S6Vf+PIgjOESBYZZ hz2kOuyTJdco/0JKsSGcIoVlTBNEDb8d/Mpg8uDaHGZihW8D4Aro+51FqXAqNp3mjMvi o7D1GSpuIHUc5pHDzF9IJ2N/IMV0sXeySnmo+3/eTa6hZqoWAv3kQ4V2PWNxjyzx2g1u DJ+0nmJrsqDoJpJWlyqPEKpVXsJ3gpXiqkBBudfBoazQHR0G9/NSoRf11F/rJC5xtQ5w gzmI3MSLbcvgfflou3dk0dUbhZM8mKiWbFC126Qq8MkgJD3Lkh9nJ3IoET6h4M+061Y2 wUDg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1773999162; x=1774603962; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-gg:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=OM7qYlf9HKURWz/+a3T3Y3rxMadnxIAJ8Nie9c0bxzE=; b=rss9eWg2uT34I7oTfsXuoOy7wZ4cUcEJmbwAK556wZVTj3JIsTfCFsV7w8tuR2/sXt JHjU9SvX5w+Ab6y5gLE9FfK/7NIg8Mqn8DXqdDxcv4FU9mTL4iOvvvNBRmgZchdBYrRs t+C8pbb3/cGIQ4+j9Ge1iPosaR0tBaglv2zAcypQ7gaOH+3hI+3BLdLck0D6FUvSwxEk 3DjA0LM91HVBbvitmo9baIQzjfrzRtg3FAtxZhtON0xfrFGffB73c5l0P6KoZacm2f5p I1k5/nNLUHLV8XJq69AsTyKPuwuLdex6xkehL4q3R74j38kiJ+cBrKy5HATt5w5Pwnsm 4KdA== X-Forwarded-Encrypted: i=1; AJvYcCVeXW7D4OXRmgnKwCcb33Pw42jUzYNGx0RXI7HsYkFEwFKMLR2yXhvCBNsgK6NNJhdlEnL8ykS/J6AzGG8=@vger.kernel.org X-Gm-Message-State: AOJu0YxCB34w8bwzutyFkpFBLAE3hKiJO68+SXwlRsMx46C8pK78G/qy oSaNbtJOQEscioR9+KAx80lywTWmefnQItMTxrItQzL21LnCNyBfbp5fZIS3U7x5JcI= X-Gm-Gg: ATEYQzx6G++iqUwVMSGLUeDUdsTutBbkFJAbrgPmWIvOJQWglSj3kRBSoFbBaifGkwq e/05Y4p+wMIZGuwHU1vR10kQ7bLers7/Z0HMnwlcXk7Bz5rSRVmFaizyxvKf+mF3U+8alrfVrnx X1eA0JYh6HoHvq62JN6s42XK9KxOr+9/IUyDQSnHdHf8shqr2tDQ7qTuT5NS84i0onBY6rQVYLO 5tO9YfSNHhPdSYzR4/FEL+iSE2NLEXEPzO4Nby32DtusJ5up5kykzkxlCVoZco1p33u4ay9o+BU +sLt76LZjClPA0NEan59+0Or3jq7M79hqeqXO3AMzXOvkLhU2bfgOYrsWTq/lr1rZEgrGgM1obB An0tnP+lQYGZKwlMad5E2OBbq3+CngI/NcSQzCcudkYWAQCvbsfzYXPk83XD5Djwm3ODNpRfyL+ 8GvCWqO954r3Q2a32LKDx1gfc2yG65dty17g== X-Received: by 2002:a05:6000:608:b0:439:fdd5:10b5 with SMTP id ffacd0b85a97d-43b6426d710mr4221954f8f.39.1773999162404; Fri, 20 Mar 2026 02:32:42 -0700 (PDT) Received: from localhost (109-81-88-11.rct.o2.cz. [109.81.88.11]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-43b64703c27sm5170510f8f.18.2026.03.20.02.32.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 20 Mar 2026 02:32:41 -0700 (PDT) Date: Fri, 20 Mar 2026 10:32:40 +0100 From: Michal Hocko To: Bing Jiao Cc: akpm@linux-foundation.org, axelrasmussen@google.com, baohua@kernel.org, bhe@redhat.com, cgroups@vger.kernel.org, chrisl@kernel.org, david@kernel.org, hannes@cmpxchg.org, joshua.hahnjy@gmail.com, kasong@tencent.com, linux-kernel@vger.kernel.org, linux-mm@kvack.org, ljs@kernel.org, muchun.song@linux.dev, nphamcs@gmail.com, rientjes@google.com, roman.gushchin@linux.dev, shakeel.butt@linux.dev, shikemeng@huaweicloud.com, weixugc@google.com, yosry@kernel.org, youngjun.park@lge.com, yuanchu@google.com, zhengqi.arch@bytedance.com Subject: Re: [PATCH v3] mm/memcontrol: fix reclaim_options leak in try_charge_memcg() Message-ID: References: <20260318215629.2849052-1-bingjiao@google.com> <20260318221957.2979346-1-bingjiao@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: On Fri 20-03-26 03:39:40, Bing Jiao wrote: > On Thu, Mar 19, 2026 at 10:29:15AM +0100, Michal Hocko wrote: > > On Wed 18-03-26 22:19:46, Bing Jiao wrote: > > > In try_charge_memcg(), the 'reclaim_options' variable is initialized > > > once at the start of the function. However, the function contains a > > > retry loop. If reclaim_options were modified during an iteration > > > (e.g., by encountering a memsw limit), the modified state would > > > persist into subsequent retries. > > > > > > This leads to incorrect reclaim behavior. Specifically, > > > MEMCG_RECLAIM_MAY_SWAP is cleared when the combined memcg->memsw limit > > > is reached. After reclaimation attemps, a subsequent retry may > > > successfully charge memcg->memsw but fail on the memcg->memory charge. > > > In this case, swapping should be permitted, but the carried-over state > > > prevents it. > > > > Have you noticed this happening in practice or is this based on the code > > reading? > > Hi, Michal, thanks for the ack. > > This issue was identified during code reading, when I was analyzing > the memsw limit behavior in try_charge_memcg(); specifically how > retries are handled when demotion is disabled (the demotion patch > itself was dropped). OK, that is always good to clarify in the changelog. -- Michal Hocko SUSE Labs