Information is stored in the receive buffer as long as it does not overrun. Overrun is prevented by setting TCP Receive Window size ( https://en.wikipedia.org/wiki/TCP_tuning#Window_size ). If packets have maximal size receive buffer is able to hold only one packet.
maximum packet size for a TCP connection
So packets are initially stored in a receive buffer ( this is Network Layer in the OSI model ) From this receive buffer they are fetched by higher layers in the OSI model i.e. TCP ( Transport Layer in OSI model ) followed by removing headers to get the data / payload...
If the packets currently in the receive buffer are not fetched they are overwritten by newly incoming packets. So if speed of data processing is not fast enough information is lost,any newly incoming packet overwrites the old packet(s) in the receive buffer .
https://en.wikipedia.org/wiki/OSI_model
In https://www.cubrid.org/blog/understanding-tcp-ip-network-stack this is described in detail
Data Receiving
Now, let's take a look at how data is received. Data receiving is a
procedure for how the network stack handles a packet coming in. Figure
3 shows how the network stack handles a packet received.
First, the NIC writes the packet onto its memory. It checks whether
the packet is valid by performing the CRC check and then sends the
packet to the memory buffer of the host. This buffer is a memory that
has already been requested by the driver to the kernel and allocated
for receiving packets. After the buffer has been allocated, the driver
tells the memory address and size to the NIC. When there is no host
memory buffer allocated by the driver even though the NIC receives a
packet, the NIC may drop the packet.
After sending the packet to the host memory buffer, the NIC sends an
interrupt to the host OS.
Then, the driver checks whether it can handle the new packet or not.
So far, the driver-NIC communication protocol defined by the
manufacturer is used.
When the driver should send a packet to the upper layer, the packet
must be wrapped in a packet structure that the OS uses for the OS to
understand the packet. For example, sk_buff of Linux, mbuf of
BSD-series kernel, and NET_BUFFER_LIST of Microsoft Windows are the
packet structures of the corresponding OS. The driver sends the
wrapped packets to the upper layer.
The Ethernet layer checks whether the packet is valid and then
de-multiplexes the upper protocol (network protocol). At this time, it
uses the ethertype value of the Ethernet header. The IPv4 ethertype
value is 0x0800. It removes the Ethernet header and then sends the
packet to the IP layer.
The IP layer also checks whether the packet is valid. In other words,
it checks the IP header checksum. It logically determines whether it
should perform IP routing and make the local system handle the packet,
or send the packet to the other system. If the packet must be handled
by the local system, the IP layer de-multiplexes the upper protocol
(transport protocol) by referring to the proto value of the IP header.
The TCP proto value is 6. It removes the IP header and then sends the
packet to the TCP layer.
Like the lower layer, the TCP layer checks whether the packet is
valid. It also checks the TCP checksum. As mentioned before, since the
current network stack uses the checksum offload, the TCP checksum is
computed by NIC, not by the kernel.
Then it searches the TCP control block where the packet is connected.
At this time, <source IP, source port, target IP, target port>
of the
packet is used as an identifier. After searching the connection, it
performs the protocol to handle the packet. If it has received new
data, it adds the data to the receive socket buffer. According to the
TCP state, it can send a new TCP packet (for example, an ACK packet).
Now TCP/IP receiving packet handling has completed.
The size of the receive socket buffer is the TCP receive window. To a
certain point, the TCP throughput increases when the receive window is
large. In the past, the socket buffer size had been adjusted on the
application or the OS configuration. The latest network stack has a
function to adjust the receive socket buffer size, i.e., the receive
window, automatically.
When the application calls the read system call, the area is changed
to the kernel area and the data in the socket buffer is copied to the
memory in the user area. The copied data is removed from the socket
buffer. And then the TCP is called. The TCP increases the receive
window because there is new space in the socket buffer. And it sends a
packet according to the protocol status. If no packet is transferred,
the system call is terminated.