Shared memory cleaning method and apparatus, electronic device, and medium

By setting the shared memory state in multi-process communication, the problem of incomplete shared memory cleanup is solved, and system performance and resource utilization are improved by automatically checking and cleaning up unused memory.

CN115373853BActive Publication Date: 2026-03-20APOLLO INTELLIGENT DRIVING (BEIJING) TECHNOLOGY CO LTD
View PDF 2 Cites 0 Cited by

Patent Information

Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2022-09-05
Publication Date
2026-03-20

AI Technical Summary

Technical Problem

In multi-process communication scenarios, existing technologies struggle to automate and effectively clean up shared memory, resulting in high storage space consumption and communication costs, and an unfriendly user experience.

Method used

The activity of shared memory is checked by setting its state. The first and second states represent the process's right to use the shared memory, respectively, and unused shared memory is automatically cleaned up.

Benefits of technology

It improves the automation of shared memory cleanup, reduces network communication costs, enhances system resource utilization, and increases sequential access throughput by 200% to 300%.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN115373853B_ABST
    Figure CN115373853B_ABST
Patent Text Reader

Abstract

The present disclosure provides a shared memory cleaning method and device, electronic equipment, computer readable storage medium and computer program product, relates to the field of computers, and particularly relates to the fields of data storage and cross-process communication technology. The implementation scheme is as follows: in response to the start of a first process, determining whether there is shared memory corresponding to the first process; in response to determining that there is shared memory corresponding to the first process, determining whether the shared memory is occupied by a second process by setting the state of the shared memory to a first state through a configuration operation, the first state being a state for checking whether the second process has the right to use the shared state; and in response to determining that the shared memory is not occupied by the second process, cleaning the shared memory.
Need to check novelty before this filing date? Find Prior Art

Description

TECHNICAL FIELD

[0001] The present disclosure relates to the field of computers, in particular to the field of data storage and cross-process communication, and more particularly to a shared memory cleaning method and device, an electronic device, a computer readable storage medium and a computer program product. BACKGROUND

[0002] In order to improve the data processing efficiency of the deep learning framework, multiple processes can be used to process data in parallel, for example, when a model is trained to load data from a disk, in order to improve the data loading efficiency, multiple processes can be supported to load data, accordingly, inter-process data sharing needs to be supported to achieve ideal data asynchronous processing efficiency. In the scenario of cross-process communication using shared memory between multiple processes, the shared memory needs to be cleaned after communication is completed to release invalid shared memory in time. SUMMARY

[0003] The present disclosure provides a shared memory cleaning method and device, an electronic device, a computer readable storage medium and a computer program product.

[0004] According to an aspect of the present disclosure, a shared memory cleaning method is provided, comprising: in response to the start of a first process, determining whether there is a shared memory corresponding to the first process; in response to determining that there is a shared memory corresponding to the first process, determining whether the shared memory is occupied by a second process through a configuration operation of setting the state of the shared memory to a first state, wherein the first state is a state of checking whether the second process has the use right of the shared state; and in response to determining that the shared memory is not occupied by the second process, cleaning the shared memory.

[0005] According to another aspect of the present disclosure, a shared memory cleaning device is provided, comprising: a first determination unit configured to determine whether there is a shared memory corresponding to a first process in response to the start of the first process; a second determination unit configured to determine whether the shared memory is occupied by a second process through a configuration operation of setting the state of the shared memory to a first state in response to determining that there is a shared memory corresponding to the first process, wherein the first state is a state of checking whether the second process has the use right of the shared state; and a cleaning unit configured to clean the shared memory in response to determining that the shared memory is not occupied by the second process.

[0006] According to another aspect of the present disclosure, an electronic device is provided, comprising: at least one processor; and a memory communicatively connected with the at least one processor; the memory stores instructions executable by the at least one processor, and the instructions are executed by the at least one processor to enable the at least one processor to execute the method described in the present disclosure.

[0007] According to another aspect of the present disclosure, there is provided a non-transitory computer readable storage medium storing computer instructions for causing a computer to perform the method described in the present disclosure.

[0008] According to another aspect of the present disclosure, there is provided a computer program product comprising a computer program which, when executed by a processor, implements the method described in the present disclosure.

[0009] According to one or more embodiments of the present disclosure, by setting the first state and the second state to the shared memory, the activity of the shared memory can be conveniently checked, and the useless shared memory can be cleared, with high automation and friendliness to users.

[0010] It should be understood that the contents described in this section are not intended to identify key or important features of the embodiments of the present disclosure, nor to limit the scope of the present disclosure. Other features of the present disclosure will become apparent through the following description. BRIEF DESCRIPTION OF DRAWINGS

[0011] The accompanying drawings illustrate exemplary embodiments and constitute a part of the specification. Together with the written description, the drawings serve to explain exemplary implementations of the embodiments. The illustrated embodiments are merely examples and do not limit the scope of the claims. In all the drawings, like reference numerals refer to like but not necessarily identical elements.

[0012] Figure 1 A schematic diagram of an exemplary system in which the various methods described herein can be implemented according to embodiments of the present disclosure is shown;

[0013] Figure 2 A flowchart of a shared memory cleaning method according to embodiments of the present disclosure is shown;

[0014] Figure 3 A process start flowchart according to embodiments of the present disclosure is shown;

[0015] Figure 4 A structural block diagram of a shared memory cleaning apparatus according to embodiments of the present disclosure is shown; and

[0016] Figure 5 A structural block diagram of an exemplary electronic device that can be used to implement embodiments of the present disclosure is shown. DETAILED DESCRIPTION

[0017] Exemplary embodiments of the present disclosure are described herein below with reference to the accompanying drawings, in which various details are set forth by way of illustration. However, it will be apparent to those skilled in the art that the embodiments described herein are susceptible to various changes and modifications without departing from the scope of the present disclosure. Also, descriptions of well-known functions and constructions are omitted for clarity and conciseness.

[0018] In the present disclosure, the terms "first", "second", and the like are used to describe various elements only for the purpose of distinguishing one element from another, and do not intend to limit the positions, sequence, or importance of the elements. In some examples, a first element and a second element can refer to the same instance of the element, and in some cases, they can refer to different instances of the element based on the context of the description.

[0019] The terms used in the description of various described examples in the present disclosure are only for the purpose of describing particular examples and are not intended to be limiting. Unless specifically defined otherwise, an element that is a singular can be plural and vice versa. Also, the term "and / or" used in the present disclosure encompasses any and all possible combinations of the listed items.

[0020] Embodiments of the present disclosure will be described in detail below with reference to the accompanying drawings.

[0021] Figure 1 A schematic diagram of an example system 100 in which various methods and apparatuses described herein can be implemented according to embodiments of the present disclosure is shown. Referring to Figure 1 The system 100 includes one or more client devices 101, 102, 103, 104, 105, and 106, a server 120, and one or more communication networks 110 that couple the one or more client devices to the server 120. The client devices 101, 102, 103, 104, 105, and 106 can be configured to execute one or more application programs.

[0022] In embodiments of the present disclosure, the server 120 can run one or more services or software applications that enable the execution of a shared memory clean-up method.

[0023] In certain embodiments, the server 120 can also provide other services or software applications, which can include non-virtual environments and virtual environments. In certain embodiments, these services can be provided as web-based services or cloud services, for example, to users of the client devices 101, 102, 103, 104, 105, and / or 106 under a software-as-a-service (SaaS) model.

[0024] In Figure 1 In the illustrated configuration, the server 120 can include one or more components that implement functionality performed by the server 120. These components can include software components that are executable by one or more processors, hardware components, or a combination thereof. Users operating the client devices 101, 102, 103, 104, 105, and / or 106 can in turn utilize one or more client applications to interact with the server 120 to utilize the services provided by these components. It should be understood that various different system configurations are possible, which can differ from the system 100. Thus, Figure 1 is one example of a system for implementing the various methods described herein and is not intended to be limiting.

[0025] A user can use the client devices 101, 102, 103, 104, 105, and / or 106 to implement the cleaning of shared memory, or the user can use the server 120 to implement the cleaning of shared memory. The client devices can provide an interface that enables a user of the client device to interact with the client device. The client devices can also output information to the user via the interface. Although Figure 1 Only six client devices are depicted, but one of skill in the art will appreciate that the present disclosure can support any number of client devices.

[0026] The client devices 101, 102, 103, 104, 105, and / or 106 can include various types of computer devices, such as portable handheld devices, general purpose computers (such as personal computers and laptop computers), workstation computers, wearable devices, smart screen devices, self-service kiosk devices, service robots, gaming systems, thin clients, various messaging devices, sensors or other sensing devices, and the like. These computer devices can run various types and versions of software applications and operating systems, such as MICROSOFT Windows, APPLE iOS, UNIX-like operating systems, Linux or Linux-like operating systems (such as GOOGLE Chrome OS); or include various mobile operating systems, such as MICROSOFT Windows Mobile OS, iOS, Windows Phone, Android. Portable handheld devices can include cellular telephones, smartphones, tablet computers, personal digital assistants (PDAs), and the like. Wearable devices can include head-mounted displays (such as smart glasses) and other devices. Gaming systems can include various handheld gaming devices, Internet-enabled gaming devices, and the like. The client devices are capable of executing various different applications, such as various Internet-related applications, communication applications (such as email applications), short message service (SMS) applications, and can use various communication protocols.

[0027] Network(s) 110 can be any type of network familiar to those skilled in the art that can support data communications using any of a variety of available protocols, including without limitation TCP / IP, SNA, IPX, etc. As examples, one or more of networks 110 can be a LAN, an Ethernet network, a Token Ring network, a WAN, the Internet, a virtual network, a virtual private network (VPN), an intranet, an extranet, a public switched telephone network (PSTN), an infrared network, a wireless network (e.g., a Bluetooth network, a WIFI network), and / or any combination of these and / or other networks.

[0028] Server 120 can include one or more general purpose computers, special purpose server computers (e.g., PC (personal computer) servers, UNIX servers, mid-range servers, mainframe computers), server clusters, or any other appropriate arrangement and / or combination. Server 120 can include one or more virtual machines running virtual operating systems, or other computing architectures involving virtualization (e.g., one or more flexible pools of logical storage devices that can be virtualized to maintain virtual storage devices for servers). In various embodiments, server 120 can be adapted to run one or more services or software applications providing the functionality described below.

[0029] Computing units in server 120 can run one or more operating systems, including any of the operating systems described above, as well as any commercially available server operating systems. Server 120 can also run any of a variety of additional server applications and / or mid-tier applications, including HTTP servers, FTP servers, CGI servers, JAVA servers, database servers, etc.

[0030] In some implementations, server 120 can include one or more applications to analyze and consolidate data feeds and / or event updates from users of client devices 101, 102, 103, 104, 105, and 106. Server 120 can also include one or more applications to display the data feeds and / or real-time events via one or more display devices of client devices 101, 102, 103, 104, 105, and 106.

[0031] In some embodiments, the server 120 can be a server of a distributed system, or a server incorporating a blockchain. The server 120 can also be a cloud server, or an intelligent cloud computing server or intelligent cloud host incorporating artificial intelligence technology. The cloud server is a host product in the cloud computing service system, to solve the defects of large management difficulty and weak business scalability in traditional physical host and virtual private server (VPS, Virtual Private Server) services.

[0032] The system 100 can also include one or more databases 130. In certain embodiments, these databases can be used to store data and other information. For example, one or more of the databases 130 can be used to store information such as process identifications. The databases 130 can reside at various locations. For example, databases used by the server 120 can be local to the server 120 or can be remote from the server 120 and can communicate with the server 120 via a network- or application-specific connection. The databases 130 can be of different types. In certain embodiments, databases used by the server 120 can be, for example, relational databases. One or more of these databases can store, update, and retrieve data to and from the databases in response to commands.

[0033] In certain embodiments, one or more of the databases 130 can also be used by applications to store application data. Databases used by applications can be databases of different types, such as key-value stores, object stores, or regular stores supported by file systems.

[0034] Figure 1 The system 100 of the present disclosure can be configured and operated in various ways to enable the application of various methods and apparatuses described in accordance with the present disclosure.

[0035] Shared memory, as the name implies, is a memory that allows two unrelated processes to access the same logical memory. Shared memory is a very effective way for two or more running processes to share and transfer data. The memory shared between different processes is usually the same physical memory. Processes can connect the same physical memory to their own address space, and all processes can access the addresses in the shared memory. If a process writes data to the shared memory, the changes will immediately affect any other process that can access the same shared memory.

[0036] For example, in a Linux system, each process has its own process control block (PCB) and address space (Addr Space), and has a corresponding page table responsible for mapping the process's virtual address to physical address, which is managed by a memory management unit (MMU). Two different virtual addresses are mapped to the same region in the physical space through the page table, and the region they point to is the shared memory.

[0037] Generally, after the multi-process communication is completed, the last process will automatically clean up its corresponding shared memory to prevent memory occupation. When the related program is started next time, the shared memory is created again. However, when an abnormality occurs in a process and the process exits, the corresponding shared memory cannot be cleaned up in time. These shared memories that are not cleaned up in time will occupy storage space. In some examples, the uncleaned shared memory can be manually cleaned up, but this way relies on manual operation, has low automation, and has cleaning risks, high communication cost, is not user-friendly, and has poor usability.

[0038] Therefore, according to an embodiment of the present disclosure, a shared memory cleaning method is provided. Figure 2 A flowchart of a shared memory cleaning method according to an embodiment of the present disclosure is shown in FIG. 2. Figure 2 As shown in FIG. 2, the method 200 includes: in response to a first process being started, determining whether there is a shared memory corresponding to the first process (step 210); in response to determining that there is a shared memory corresponding to the first process, determining whether the shared memory is occupied by a second process by setting a state of the shared memory to a first state, wherein the first state is a state of checking whether the second process has a usage right to the shared state (step 220); and in response to determining that the shared memory is not occupied by the second process, cleaning up the shared memory (step 230).

[0039] According to an embodiment of the present disclosure, by setting the first state for the shared memory, the activity of the shared memory can be conveniently checked, and then the useless shared memory can be cleaned up, which has high automation and is more user-friendly.

[0040] In cross-process communication, a process has to first allocate a shared memory before it can use it. Different processes can simultaneously map the same memory page into their own address space, thus achieving the purpose of sharing memory. After the communication is completed, all processes will detach from the shared memory, and a process will release the shared memory block. Allocating a new shared memory block creates a new memory page. Because all processes want to share access to the same block of memory, only one process should create a new shared memory. Allocating an already existing memory block again will not create a new page, but will only return an identifier that identifies the memory block. If a process wants to use this shared memory block, it first needs to bind it to its own address space. This creates a mapping from the process's own virtual address to the shared page. When the use of the shared memory is over, this mapping is deleted. When no process needs to use this shared memory block any more, one (and only one) process is responsible for releasing the shared memory page.

[0041] According to some embodiments, the second process is configured to set a state of the shared memory to a second state that is mutually exclusive with the first state before using the shared memory, wherein the second state is a state indicating that the second process has the right to use the shared memory.

[0042] In the present disclosure, it can be understood that the "first process" is a process that has not successfully mapped the shared memory in the program startup, and the "second process" is a process that has successfully mapped the shared memory. At this time, the state of the shared memory needs to be set to a second state that is mutually exclusive with the first state, to indicate that the second process has the right to use the shared memory. It can be seen that the current "first process" can be converted to the "second process" in the subsequent stage.

[0043] According to some embodiments, determining whether the shared memory corresponding to the first process exists in the system comprises: determining whether the shared memory corresponding to the first process exists in the system based on the shared memory identifier.

[0044] Specifically, in some examples, the shared memory is created through a standard system call, the interface (such as shm_open, shm_get, etc.) has process safety properties, multiple processes pass in the same shared memory identifier (i.e. identity ID), and only one process will create the shared memory, and the memory initialization is performed by the process that creates the shared memory, and other processes map the already allocated memory address to their own process space, and then wait for the memory initialization to be completed.

[0045] For example, the shared memory can be allocated by the following function: int segment_id = shmget(shm_key, int size, shmflag). The first parameter of the function is a key value used to identify the shared memory block. Processes independent of each other can obtain access to the same shared memory block by specifying the same key; the second parameter of the function specifies the size of the memory block to be applied for, because the memory blocks are allocated in page units, the actual size of the memory block to be allocated will be expanded to an integer multiple of the page size; the third parameter is a set of flags, which are combined by bitwise OR operation with specific constants to be used in the shmget.

[0046] It is of course understood that other forms of functions that can be used to allocate shared memory are possible, and are not limited herein.

[0047] According to some embodiments, the first state and the second state are file descriptors. Processes that successfully map the shared memory all need to configure the shared memory state through a system call, i.e., the second state indicating that the process has the right to use the shared memory. The file descriptor can also have a first state that is mutually exclusive with the second state. At this time, the existing shared memory file descriptor can be borrowed, or other file descriptors can be used to achieve the function, and are not limited herein. This file descriptor can be referred to as a state file descriptor. After the corresponding process exits or crashes, the second state configured by the process will also disappear, indicating that the process has no control over the shared memory at this time.

[0048] Different operating systems and different file descriptors can be configured through respective interfaces. For example, under a Linux system or a Unix system, according to some embodiments, the state of the shared memory can be configured through the flock interface, and the first state is LOCK_EX state and the second state is LOCK_SH state.

[0049] According to some embodiments, the method 200 can further include, after cleaning up the shared memory, recreating the shared memory corresponding to the first process based on the shared memory identifier. That is, after the shared memory is cleaned up, the normal new shared memory phase is entered.

[0050] According to some embodiments, the method 200 can further include, in response to determining that the shared memory corresponding to the first process does not exist, recreating the shared memory corresponding to the first process based on the shared memory identifier. That is, the determination that the shared memory corresponding to the first process does not exist indicates that the shared memory has been successfully cleaned up in the previous program execution process, and at this time the first process can directly enter the normal new shared memory phase.

[0051] According to some embodiments, before determining whether the shared memory is occupied by a second process by setting the state of the shared memory to a first state, the method further includes: delaying for a preset time period. By delaying for a preset time period before checking memory activity, other potential impacts on the system can be reduced, and the accuracy of detecting memory to be cleaned can be improved.

[0052] Figure 3 A process startup flowchart according to an embodiment of the present disclosure is shown. Figure 3 As shown, after the first process starts, it first checks if there is any existing shared memory in the current system. If the shared memory does not exist, it is created. If the shared memory exists, it waits for a certain period of time, such as 0.5s, 1s, 1.5s, etc., and then checks the activity of the shared memory (whether it is being used by other processes). Memory activity is checked by writing a first status flag (i.e., ...) to the status file descriptor. Figure 3 The write-shared identifier shown here does not indicate that a write operation can be performed on the shared memory; it merely indicates a state that is mutually exclusive with the read-shared identifier, which indicates the right to use the shared memory. As mentioned above, the first and second states are mutually exclusive, and only one process can write to the first state identifier. If the write fails, it indicates that the shared memory is being used and cannot be cleaned up, so the process enters the open existing shared memory stage; if the write succeeds, it indicates that no process is using the shared memory and the existing shared memory needs to be cleaned up, so the existing shared memory is cleaned up. After the shared memory is cleaned up, the normal new shared memory stage begins, and the second state identifier (i.e., ...) is written when the memory is successfully created. Figure 3 The shared memory identifier shown here does not indicate that a read operation can be performed on the shared memory; it merely indicates that the user has the right to use the shared state. Successfully created processes perform process initialization, while other processes wait for initialization to complete.

[0053] Multiple processes can set a second state for the same shared memory, marking it as usable. This state becomes idle when all processes exit. The operating system automatically clears this second state flag when a process exits abnormally. Only one process can set the first state of shared memory. When the shared memory is being used normally by other processes, setting it to the first state will consistently fail due to the existence of the second state set by those processes. Setting the first state will only succeed if a process exits abnormally and the shared memory is not cleared.

[0054] According to the embodiments of the present disclosure, the problem that the sequential access throughput cannot be improved and broken through due to the network communication cost (latency and failure) can be effectively reduced, so that the sequential access throughput of the whole system is not affected by the cross-IDC (Internet Data Center) and network topology, and the utilization rate of the system to the resources is greatly improved. The sequential access throughput is improved by 200% to 300% in the real online system.

[0055] According to the embodiments of the present disclosure, as Figure 4 shown, a shared memory cleaning device 400 is also provided, which comprises: a first determining unit 410, configured to determine whether there is a shared memory corresponding to a first process in response to the start of the first process; a second determining unit 420, configured to determine whether the shared memory is occupied by a second process by setting the state of the shared memory to a first state through a configuration operation in response to determining that there is a shared memory corresponding to the first process, wherein the first state is a state for checking whether the second process has the use right of the shared state; and a cleaning unit 430, configured to clean the shared memory in response to determining that the shared memory is not occupied by the second process.

[0056] Here, the operations of the above-mentioned units 410-430 of the shared memory cleaning device 400 are similar to the operations of the steps 210-230 described above, and will not be described here again.

[0057] According to the embodiments of the present disclosure, an electronic device, a readable storage medium and a computer program product are also provided.

[0058] Referring to Figure 5 , a structural block diagram of an electronic device 500 that can be a server or a client of the present disclosure will now be described, which is an example of a hardware device that can be applied to various aspects of the present disclosure. The electronic device is intended to represent a variety of forms of digital electronic computing devices, such as laptops, desktops, workstations, personal digital assistants, servers, blade servers, mainframes, and other suitable computers. The electronic device can also represent a variety of forms of mobile devices, such as personal digital processing, cellular phones, smart phones, wearable devices, and other similar computing devices. The components shown herein, their connections, and relationships, and their functions, are merely examples and are not intended to limit implementations of the present disclosure described and / or claimed herein.

[0059] As Figure 5As shown, the electronic device 500 includes a computing unit 501 that can perform various appropriate actions and processes in accordance with a computer program stored in a read only memory (ROM) 502 or a computer program loaded into a random access memory (RAM) 503 from a storage unit 508. Various programs and data required for the operation of the electronic device 500 can also be stored in the RAM 503. The computing unit 501, the ROM 502, and the RAM 503 are connected to each other through a bus 504. An input / output (I / O) interface 505 is also connected to the bus 504.

[0060] A plurality of components in the electronic device 500 are connected to the I / O interface 505, including an input unit 506, an output unit 507, a storage unit 508, and a communication unit 509. The input unit 506 can be any type of device that can input information to the electronic device 500, can receive inputted digital or character information, and generate key signal inputs related to user settings and / or function controls of the electronic device, and can include, but is not limited to, a mouse, a keyboard, a touch screen, a track pad, a track ball, a joystick, a microphone, and / or a remote controller. The output unit 507 can be any type of device that can present information, and can include, but is not limited to, a display, a speaker, a video / audio output terminal, a vibrator, and / or a printer. The storage unit 508 can include, but is not limited to, a magnetic disk, an optical disk. The communication unit 509 allows the electronic device 500 to exchange information / data with other devices through a computer network such as the Internet and / or various telecommunication networks, and can include, but is not limited to, a modem, a network card, an infrared communication device, a wireless communication transceiver, and / or a chipset, such as a Bluetooth™ device, an 802.11 device, a WiFi device, a WiMax device, a cellular communication device, and / or the like.

[0061] The computing unit 501 can be various general and / or special purpose processing components with processing and computing capabilities. Some examples of the computing unit 501 include, but are not limited to, a central processing unit (CPU), a graphics processing unit (GPU), various specialized artificial intelligence (AI) computing chips, various computing units running machine learning model algorithms, a digital signal processor (DSP), and any appropriate processor, controller, microcontroller, etc. The computing unit 501 performs various methods and processes described above, such as the method 200. For example, in some embodiments, the method 200 can be implemented as a computer software program tangibly embodied in a machine-readable medium, such as the storage unit 508. In some embodiments, part or all of the computer program can be loaded and / or installed onto the electronic device 500 via the ROM 502 and / or the communication unit 509. When the computer program is loaded onto the RAM 503 and executed by the computing unit 501, one or more steps of the method 200 described above can be performed. Alternatively, in other embodiments, the computing unit 501 can be configured to perform the method 200 by any other appropriate means, such as by means of firmware.

[0062] Various implementations of the systems and techniques described above can be realized in digital electronic circuitry, integrated circuitry, a field programmable gate array (FPGA), an application specific integrated circuit (ASIC), a system on a chip (SOC), a complex programmable logic device (CPLD), computer hardware, firmware, software, and / or combinations thereof. These various implementations can include implementation in one or more computer programs that are executable and / or interpretable on a programmable system including at least one programmable processor, which can be special or general purpose, coupled to receive data and instructions from, and to transmit data and instructions to, a storage system, at least one input device, and at least one output device.

[0063] Program code for carrying out methods of the present disclosure can be written in any combination of one or more programming languages. The program code can be provided to a processor or controller of a general purpose computer, special purpose computer, or other programmable data processing apparatus to produce a machine, such that the program code, when executed by the processor or controller, produces the functions / operations specified in the flowcharts and / or the block diagrams. The program code can be executed entirely on a machine, partially on a machine, partially on a machine and partially on a remote machine or entirely on a remote machine or server.

[0064] In the context of this disclosure, a machine-readable medium can be a tangible medium that contains or stores a program for use by or in connection with an instruction execution system, apparatus, or device. The machine-readable medium can be a machine-readable signal medium or a machine-readable storage medium. A machine-readable medium can include but is not limited to an electronic, magnetic, optical, electromagnetic, infrared, or semiconductor system, apparatus, or device, or any suitable combination of the foregoing. More specific examples of the machine-readable storage medium will include one or more lines of electrical connections, portable computer disks, hard disk drives, random access memory (RAM), read-only memory (ROM), erasable programmable read-only memory (EPROM or Flash memory), optical fibers, portable compact disc read-only memories (CD-ROMs), optical storage devices, magnetic storage devices, or any suitable combination of the foregoing.

[0065] To provide for interaction with a user, the systems and techniques described here can be implemented on a computer having a display device (e.g., a CRT (cathode ray tube) or LCD (liquid crystal display) monitor) for displaying information to the user and a keyboard and a pointing device (e.g., a mouse or a trackball) by which the user can provide input to the computer. Other kinds of devices can be used to provide for interaction with a user as well; for example, feedback provided to the user can be any form of sensory feedback (e.g., visual feedback, auditory feedback, or tactile feedback); and input from the user can be received in any form, including acoustic, speech, or tactile input.

[0066] The systems and techniques described here can be implemented in a computing system that includes a back end component (e.g., as a data server), or that includes a middleware component (e.g., an application server), or that includes a front end component (e.g., a user computer having a graphical user interface or a Web browser through which a user can interact with an implementation of the systems and techniques described here), or any combination of such back end, middleware, or front end components. The components of the system can be interconnected by any form or medium of digital data communication (e.g., a communication network). Examples of communication networks include a local area network (LAN), a wide area network (WAN), the Internet, and a blockchain network.

[0067] The computer system can include clients and servers. This relationship can be remote or on-site. The servers can be cloud servers, servers of a distributed system, or servers combined with a blockchain.

[0068] It should be understood that the various forms of flow shown above can be used to reorder, add, or remove steps. For example, the steps described in the present disclosure can be performed in parallel, sequentially, or in a different order, as long as the desired results of the technical solutions disclosed in the present disclosure can be achieved, which are not limited herein.

[0069] Although embodiments or examples of the present disclosure have been described with reference to the accompanying drawings, it should be understood that the above-described methods, systems, and devices are merely exemplary embodiments or examples, and the scope of the present disclosure is not limited by these embodiments or examples, but only by the granted claims and their equivalent scope. Various elements in the embodiments or examples can be omitted or replaced by equivalent elements. In addition, each step can be performed in an order different from that described in the present disclosure. Further, various elements in the embodiments or examples can be combined in various ways. It is important that many of the elements described herein can be replaced by equivalent elements that appear after the present disclosure as technology evolves.

Claims

1. A shared memory cleanup method, comprising: In response to the startup of the first process, determine whether there is shared memory corresponding to the first process; In response to determining the existence of shared memory corresponding to the first process, a configuration operation is performed to set the state of the shared memory to a first state to determine whether the shared memory is occupied by the second process. The first state is a state used to verify whether the second process has the right to use the shared memory. Before using the shared memory, the second process is configured to set the state of the shared memory to a second state mutually exclusive with the first state. The second state indicates that the second process has the right to use the shared memory, and the second state can be automatically cleared when the second process exits abnormally. In response to determining that the state of the shared memory has been successfully set to the first state, the shared memory is cleaned up.

2. The method as described in claim 1, wherein, The first state and the second state are file descriptors.

3. The method as described in claim 2, wherein, The shared memory state is configured through the Flock interface, with the first state being LOCK_EX and the second state being LOCK_SH.

4. The method of claim 1, wherein, Before determining whether the shared memory is occupied by the second process by setting the state of the shared memory to the first state in the configuration operation, the method further includes: delaying and waiting for a preset time period.

5. The method of claim 1, wherein, Determining whether shared memory corresponding to the first process exists includes: determining whether shared memory corresponding to the first process exists based on the shared memory identifier.

6. The method of claim 5, further comprising: After cleaning up the shared memory, the shared memory corresponding to the first process is recreated based on the shared memory identifier.

7. The method of claim 5, further comprising: In response to determining that the shared memory corresponding to the first process does not exist, the shared memory corresponding to the first process is recreated based on the shared memory identifier.

8. A shared memory cleanup device, comprising: The first determining unit is configured to determine whether shared memory corresponding to the first process exists in response to the start of the first process; The second determining unit is configured to, in response to determining the existence of shared memory corresponding to the first process, determine whether the shared memory is occupied by the second process by setting the state of the shared memory to a first state, wherein the first state is a state that verifies whether the second process has the right to use the shared memory, wherein before the second process uses the shared memory, it is configured to set the state of the shared memory to a second state that is mutually exclusive with the first state, wherein the second state is a state that indicates that it has the right to use the shared memory, wherein the second state can be automatically cleared when the second process exits abnormally; as well as The cleanup unit is configured to clean up the shared memory in response to determining that the state of the shared memory has been successfully set to the first state.

9. The apparatus of claim 8, wherein, The first state and the second state are file descriptors.

10. The apparatus of claim 9, wherein, The shared memory state is configured through the Flock interface, with the first state being LOCK_EX and the second state being LOCK_SH.

11. The apparatus of claim 8, wherein, Before determining whether the shared memory is occupied by the second process by setting the state of the shared memory to the first state through a configuration operation, the method further includes: a delay unit configured to delay and wait for a preset time period.

12. The apparatus of claim 8, wherein, The first determining unit includes: a unit for determining whether shared memory corresponding to the first process exists based on a shared memory identifier.

13. The apparatus of claim 12, further comprising: The first memory creation unit is configured to recreate the shared memory corresponding to the first process based on the shared memory identifier after cleaning up the shared memory.

14. The apparatus of claim 12, further comprising: The second memory creation unit is configured to recreate the shared memory corresponding to the first process based on the shared memory identifier in response to determining that the shared memory corresponding to the first process does not exist.

15. An electronic device comprising: At least one processor; as well as A memory that is communicatively connected to the at least one processor; in The memory stores instructions that can be executed by the at least one processor to enable the at least one processor to perform the method of any one of claims 1-7.

16. A non-transitory computer-readable storage medium storing computer instructions, wherein, The computer instructions are used to cause the computer to perform the method according to any one of claims 1-7.

17. A computer program product comprising a computer program, wherein, The computer program, when executed by a processor, implements the method of any one of claims 1-7.

Citation Information

Patent Citations

  • System and method for accessing to abnormality of shared memory

    CN105389226A

  • Memory sharing method and device

    CN112906075A