From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-qv1-f54.google.com (mail-qv1-f54.google.com [209.85.219.54]) (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 B57479460 for ; Wed, 18 Mar 2026 22:54:09 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.219.54 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1773874452; cv=none; b=kDYXQjEzDJikwQurRSJE8u/mIguFY/Vx3fo+i1Cifjg0wH+s64h8znrJgyjc+RBmzoO/+O6Osh8x73xZnoowVLTLIb6c76ovHD7re2CZCXMPC/07u9O/3dP6d5ayKuxR8CEflu+VrbZW/E+vhDpS40Klu8QrrfMfEY5i1KQ5jKA= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1773874452; c=relaxed/simple; bh=rRYJnyAWFPF7AoIupo3ZJeRw5l4Ugmp6cUwc8Y7dUsY=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=V3/RUN7luFfmjmN0+/wj4yhmPtDbQvl8RRanTKHg+2wnJ0UhIiCIgSYZpeX70DSjJ8obLA24o+4XJWPFRpKgD/V78gibbt7LxPuBiV30g5VfsCWuGWQbikGSAaJfFuOeSv87mPIgrkPUVBAVOAAWL0M8n1X1cY1WbotsRotYIXo= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=cmpxchg.org; spf=pass smtp.mailfrom=cmpxchg.org; dkim=pass (2048-bit key) header.d=cmpxchg.org header.i=@cmpxchg.org header.b=Yu6FJ2LO; arc=none smtp.client-ip=209.85.219.54 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=cmpxchg.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=cmpxchg.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=cmpxchg.org header.i=@cmpxchg.org header.b="Yu6FJ2LO" Received: by mail-qv1-f54.google.com with SMTP id 6a1803df08f44-89a06bc2f1bso7355156d6.1 for ; Wed, 18 Mar 2026 15:54:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cmpxchg.org; s=google; t=1773874448; x=1774479248; 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=m3C6OkbYPe6oQrXzYVsFhDRac3t3GyQCJ31s/cMP59Y=; b=Yu6FJ2LONqs1hQFwz1cOzESGGbK74kXuYXASg8X9831MWYIiZoje8v0WF96toVHD16 h16vjD+nE9g1Tjyg93hPD+gWxfmdMgUmKdLWa9ULJb7qJBRM+FZYgjVPnoV26q8lM00H X4fL4fqVHrU4Bmr3gOBIzonofervOYnsj8BDoHw7rc/9Pn/vhS3mQj/k+Oz/mfRm4TCH +KgMT5yE2aiHk4Seu0tH9wP9NMTwGfhVeNX9QU7Q9n7kb4M23UsThaNjDpJGy/fm7z5a 0yy1G+W/f0h9CG+c4AnVdeGh5VEtz9RbsaU5G4exrCYjJ/pjITPJL3w8U8KY65q2+rJN NF9A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1773874448; x=1774479248; 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=m3C6OkbYPe6oQrXzYVsFhDRac3t3GyQCJ31s/cMP59Y=; b=Kweeg37xWZdqKKe9dPwDAW5pKDofgbB44R/SmjXeMSDJdo9FKKSQJEhD8XKqqoP92J RNsgj2YSFnOjp0LJ/tOokF/R7vdB5O5wGySuap/W+9WUeMpoHXnnSK1kl7AWFNsl1eH7 xdJoz73HbhxDyS1SgEX9Ejek/pvK/6f5jHd+Ah3TRVmFNnx6LuW1CCoUNbz7l3hKh1UQ QUR2axn0bPUOHxEfw004hD3Pwh00F4cP6GNRZ7utMAe51z/P4ngUZ46qBIN9DXLpGpKm okN96AwqcMqDz6t0ygM1KTgHqAYVffqYAx5AoCQYMO/FbBLsbd9OZz+RGc28vrizAsMI FoLQ== X-Forwarded-Encrypted: i=1; AJvYcCWSj0CNLRJz82KcLfWUzRJ0h7NzI/JDgqng/Nkq1R6OOhlJVQVwXzjytt0jJtcCABv/5JBx6n//7tWH0JE=@vger.kernel.org X-Gm-Message-State: AOJu0YxXGB4+E+S6Lc8u6YPWLuQgiEM7g51yiEFzaqmfyxdRCBXZWWqV O74FwDK2AmllPRUaWUmS8CVtvCzl/bglRKcP6CVLYEoWX7dzQ9b9AzIzZep0ob7DecA= X-Gm-Gg: ATEYQzya1tN8VJIZAwIqkY4ThHMhTyd6OazEm/T492lCkgWF0/R7SjAsnpl6S6V/w0r O1mwSJ+4W/C+d2JxRSynXjWvVtRfcZ/T4TvtVeZga1+hB0DfX2y7O0tGhUJ7OFdXJjxR4QESc0s y0D6sgP/kDcqbpsYUK1xOAMBXieub4A34lOdIHCjK5LKyYgcNAf20d4Rfr74KZd+iy/B/lR6dGE yb3DUqq+DN1ZfrVYxsavUJSZcu8AUtmW5quOVm1l70bU0dJ4hMNcb23PU/dkABzOlTZ4b4m26Pn lUuzxYjobzCtPb4dWLC8Mfel8DPqjge+d3OZyt6noIDWdCm3Xkd9Gr0QchYSxKW+zPWLK8biwNc u8C7PwhigvKduKTHUGCrj/iNRqUieYjAMDz1EYPpgrls7/46dxAtncxk6EnbDimWCjYlomZIZSi NbKEzbqsvNYTB3v9iyl2SLpg== X-Received: by 2002:a05:6214:3308:b0:89a:443e:d43f with SMTP id 6a1803df08f44-89c6b56249cmr69999326d6.33.1773874448372; Wed, 18 Mar 2026 15:54:08 -0700 (PDT) Received: from localhost ([2603:7000:c00:3a00:365a:60ff:fe62:ff29]) by smtp.gmail.com with ESMTPSA id 6a1803df08f44-89c6b9ce2absm31068786d6.25.2026.03.18.15.54.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 18 Mar 2026 15:54:07 -0700 (PDT) Date: Wed, 18 Mar 2026 18:54:06 -0400 From: Johannes Weiner 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, joshua.hahnjy@gmail.com, kasong@tencent.com, linux-kernel@vger.kernel.org, linux-mm@kvack.org, ljs@kernel.org, mhocko@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: <20260318221957.2979346-1-bingjiao@google.com> On Wed, Mar 18, 2026 at 10:19:46PM +0000, 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. > > Fix by moving the initialization of 'reclaim_options' inside the > retry loop, ensuring a clean state for every reclaim attempt. > > Fixes: 6539cc053869 ("mm: memcontrol: fold mem_cgroup_do_charge()") > Signed-off-by: Bing Jiao > Reviewed-by: Yosry Ahmed Acked-by: Johannes Weiner