From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail.tuxteam.de (mail.tuxteam.de [5.199.139.25]) by sourceware.org (Postfix) with ESMTPS id D7E07385771D for ; Mon, 5 Jun 2023 04:41:57 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org D7E07385771D Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=tuxteam.de Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=tuxteam.de DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=tuxteam.de; s=mail; h=From:In-Reply-To:Content-Type:MIME-Version:References:Message-ID: Subject:Cc:To: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=5od53DEECXmx/EdyNhrca0iHiCRhE2F5WgKfSuU6Q4k=; b=R7XThqsRZEfv/TJ1kXkU/af7av vRz7vwyGSaEikd7N+a4KQdJ+bqvd49iXnRKDxp2mQCHH0JoMJwqYwYl9M1JbvQGaLtVn+aT5D7a7k JBl2vbFYB42T5AA6g9E/b3xHYJrf5CETjMl7aAI35Bn+E4I01kk14kttB7QjYzRFaBhADxrYJGkvB atO4/Uyug8Y3oBcrvSn3Zz3okjBDU9l3z5OjNbQJsSe4jUBpPfkN+CBygIFbpbOeEG3gRGCV2cFLr wKPStokpfLiXDP5+jSHqnRgGZYaIvI5Y+Nmk5cghm9lk8b1GSnOuy1Ntm4f7+2tiPKB2v8q88SYk1 /XoFJiTg==; Received: from tomas by mail.tuxteam.de with local (Exim 4.94.2) (envelope-from ) id 1q622V-0003iW-Sg; Mon, 05 Jun 2023 06:41:55 +0200 Date: Mon, 5 Jun 2023 06:41:55 +0200 To: Konstantin Kharlamov Cc: libc-help@sourceware.org Subject: Re: Q: System behaviour in out of memory situation Message-ID: References: MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="sgiboCNf44iAJFeS" Content-Disposition: inline In-Reply-To: From: X-Spam-Status: No, score=-2.7 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_PASS,TXREP,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: --sgiboCNf44iAJFeS Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Mon, Jun 05, 2023 at 03:28:00AM +0300, Konstantin Kharlamov wrote: > Hi, just 2 theoretic questions: >=20 > 1. I know that calling malloc() only allocates a virtual memory, not a re= al one. It's kind of memory you can allocate Terabytes of, which some apps = do (e.g. on my system electron has 1.1T allocated). It will only turn into = a real memory by the kernel upon the app accessing it. But then, assuming O= OM-killer is disabled, what happens if I try to access such virtual memory = thus forcing it to turn into a real one, but the system is out of real memo= ry ATM? > 2. Is it unrealistic to expect ENOMEM from `malloc()`? That is because = =CE=B1) most systems have OOM-killer enabled, so instead of ENOMEM some app= will get killed =CE=B2) In absence of OOM-killer you'll get virtual memory= successfully allocated, which returns us to 1. >=20 > P.S.: I asked 1st question on #glibc OFTC on Saturday as well, but got no= reply still. So decided to give a try to the ML. I guess this is more an operating system question that a libc one. Since you are talking about the OOM killer, I further guess that your context is Linux. In this case, your magic keyword is "memory overcommitment". There is a setting for that, see for example here: https://www.kernel.org/doc/html/v5.1/vm/overcommit-accounting.html Cheers --=20 t --sgiboCNf44iAJFeS Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iF0EABECAB0WIQRp53liolZD6iXhAoIFyCz1etHaRgUCZH1njQAKCRAFyCz1etHa RviGAJ9E3AOmZiLHU2WJUtou2njUeJoUQgCfXQSAgpIQMyYLi7MgVerozG+Novk= =P1J0 -----END PGP SIGNATURE----- --sgiboCNf44iAJFeS--