CN111796944A - Method and device for switching shared memory area, storage medium and electronic equipment - Google Patents

Method and device for switching shared memory area, storage medium and electronic equipment Download PDF

Info

Publication number
CN111796944A
CN111796944A CN201910277829.9A CN201910277829A CN111796944A CN 111796944 A CN111796944 A CN 111796944A CN 201910277829 A CN201910277829 A CN 201910277829A CN 111796944 A CN111796944 A CN 111796944A
Authority
CN
China
Prior art keywords
length
shared memory
memory area
storage
data
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Pending
Application number
CN201910277829.9A
Other languages
Chinese (zh)
Inventor
戴国浩
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Vita Technology Beijing Co ltd
Original Assignee
Vita Technology Beijing Co ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Vita Technology Beijing Co ltd filed Critical Vita Technology Beijing Co ltd
Priority to CN201910277829.9A priority Critical patent/CN111796944A/en
Publication of CN111796944A publication Critical patent/CN111796944A/en
Pending legal-status Critical Current

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F9/00Arrangements for program control, e.g. control units
    • G06F9/06Arrangements for program control, e.g. control units using stored programs, i.e. using an internal store of processing equipment to receive or retain programs
    • G06F9/46Multiprogramming arrangements
    • G06F9/54Interprogram communication
    • G06F9/544Buffers; Shared memory; Pipes

Landscapes

  • Engineering & Computer Science (AREA)
  • Software Systems (AREA)
  • Theoretical Computer Science (AREA)
  • Physics & Mathematics (AREA)
  • General Engineering & Computer Science (AREA)
  • General Physics & Mathematics (AREA)
  • Information Retrieval, Db Structures And Fs Structures Therefor (AREA)

Abstract

The present disclosure aims to provide a method and an apparatus for switching a shared memory area, a storage medium, and an electronic device, so as to solve the problem in the prior art that a virtual sending end and a virtual receiving end have low performance in communication based on a host shared memory area. In order to achieve the above object, the present disclosure provides a method for switching a shared memory area, where the shared memory area is located in a host, and a virtual sending end and a virtual receiving end run on the host; the method comprises the following steps: acquiring data parameter information of communication data historically sent by the sending end; judging whether the data parameter information meets preset parameter conditions or not; and if the preset parameter conditions are met, generating an instruction for indicating to switch the shared memory area used by the sending end and the receiving end.

Description

Method and device for switching shared memory area, storage medium and electronic equipment
Technical Field
The present disclosure relates to the field of data processing, and in particular, to a method and an apparatus for switching a shared memory area, a storage medium, and an electronic device.
Background
With the development of computer technology, the communication scenes between virtual machines and virtual machines (VM-VM) and between virtual machines and a Host (VM-Host) are increasing. A common approach is to do VM-VM communication, or VM-Host communication, over a TCP/IP network. However, this method has disadvantages of high communication delay, low bandwidth, and the like. In the related art, in order to reduce the communication delay and increase the communication bandwidth, a scheme for performing communication between a virtual machine and between the virtual machine and a host by reading and writing a shared memory is proposed.
Specifically, a process a in the virtual machine 1 and a process b in the virtual machine 2 need to establish a shared memory area for communication, and the virtual machine 1 or the virtual machine 2 requests the host to establish the shared memory area. The host allocates a shared memory area 1 for the process a and the process b according to the request of the virtual machine. Further, the host inserts a new device, for example, dev/shm1a and dev/shm2b, into each of the virtual machines 1 and 2, where the read/write operations on the two devices are equivalent to the read/write operations on the shared memory area 1. The host informs the process a of the virtual machine 1 and the process b of the virtual machine 2 of the two devices (/ dev/shm1a and/dev/shm 2b), and the process a of the virtual machine 1 and the process b of the virtual machine 2 can respectively communicate through read-write operations on the two devices (/ dev/shm1a and/dev/shm 2 b).
It should be noted that the length of the shared memory area may affect the performance of the communication between VM-VM and VM-Host. This is because, when the length of the transmitted data is greater than the length of the shared memory area, the transmitted data needs to be divided into a plurality of blocks and transmitted in multiple times, and each block of data needs to be transmitted by the transmitting end and the receiving end at least once. The interactive operation process may include the following: the sending end informs the receiving end to take away the data, and the receiving end informs the sending end that the data is taken away after the data is taken away. However, such interaction between the transmitting end and the receiving end introduces additional time cost, thereby reducing the performance of data transmission.
Disclosure of Invention
The present disclosure aims to provide a method and an apparatus for switching a shared memory area, a storage medium, and an electronic device, so as to solve the problem in the prior art that a virtual sending end and a virtual receiving end have low performance in communication based on a host shared memory area.
In order to achieve the above object, the present disclosure provides a method for switching a shared memory area, where the shared memory area is located in a host, and a virtual sending end and a virtual receiving end run on the host; the method comprises the following steps:
acquiring data parameter information of communication data historically sent by the sending end;
judging whether the data parameter information meets preset parameter conditions or not;
and if the preset parameter conditions are met, generating an instruction for indicating to switch the shared memory area used by the sending end and the receiving end.
Optionally, the method further comprises:
the target duration between the time of executing the switching of the shared memory area used by the sending end and the receiving end for the last time and the current time is calculated;
the acquiring of the data parameter information of the communication data sent by the sending end in history includes:
and if the target time length is greater than a preset time length threshold value, acquiring data parameter information of communication data which are sent by the sending end in the target time length in a historical mode.
Optionally, the acquiring data parameter information of communication data historically sent by the sending end includes:
for each piece of communication data, calculating a length ratio of a data length of the communication data to a storage length, wherein the data parameter information comprises the length ratio;
the judging whether the data parameter information meets a preset parameter condition includes:
determining a maximum length ratio of the calculated length ratios;
and if the maximum length ratio is larger than a preset maximum ratio threshold, determining that the preset parameter condition is met.
Optionally, the determining whether the data parameter information meets a preset parameter condition further includes:
the length ratios obtained by calculation are arranged from small to large, and a first length ratio positioned in a first preset percentile is determined;
and if the maximum length ratio is not greater than a preset maximum ratio threshold and the first length ratio is not in a preset percentile ratio range, determining that the preset parameter condition is met.
Optionally, the method further comprises:
determining a storage length to be selected according to the parameter information and a first storage length of a first shared memory area currently used by the sending end and the receiving end;
if the storage length to be selected is smaller than the first storage length, setting the newly allocated second shared memory area as the storage length to be selected;
if the to-be-selected storage length is not smaller than the first storage length and the to-be-selected storage length is not larger than a preset storage threshold length, setting the newly allocated second shared memory area as the to-be-selected storage length;
and if the length of the storage to be selected is not less than the first storage length and is greater than a preset storage threshold length, setting the newly allocated second shared memory area as the storage threshold length.
Optionally, determining a storage length to be selected according to the parameter information and a first storage length of a first shared memory area currently used by the sending end and the receiving end; the method comprises the following steps:
determining a target coefficient according to the parameter information;
and determining the storage length to be selected according to the product of the target coefficient and the first storage length.
Optionally, the acquiring data parameter information of communication data historically sent by the sending end includes: for each piece of communication data, calculating a length ratio of a data length of the communication data to a storage length, wherein the data parameter information comprises the length ratio; the determining a target coefficient according to the parameter information includes: determining a maximum length ratio of the calculated length ratios; the length ratios obtained by calculation are arranged from small to large, and a second length ratio positioned in a second preset percentile is determined;
if the maximum length ratio and the second length ratio are not larger than a preset floating point threshold, setting a target coefficient as the second length ratio; and if any one of the maximum length ratio and the second length ratio is larger than the preset floating point threshold, setting the target coefficient as the ratio of the maximum length ratio to the floating point threshold.
Optionally, the determining the storage length to be selected according to the product of the target coefficient and the first storage length includes: and determining the storage length to be selected as a value rounded up by the product of the target coefficient and the first storage length.
The present disclosure provides a device for switching a shared memory area, where the shared memory area is located on a host, and a virtual sending end and a virtual receiving end run on the host; the device comprises:
the acquisition module is used for acquiring data parameter information of communication data which is historically sent by the sending end;
the judging module is used for judging whether the data parameter information meets a preset parameter condition or not;
and the triggering module is used for generating an instruction for indicating the switching of the shared memory area used by the sending end and the receiving end if the preset parameter condition is met.
Optionally, the apparatus further comprises a time module configured to: the target duration between the time of executing the switching of the shared memory area used by the sending end and the receiving end for the last time and the current time is calculated;
the obtaining module is configured to: and if the target time length is greater than a preset time length threshold value, acquiring data parameter information of communication data which are sent by the sending end in the target time length in a historical mode.
Optionally, the obtaining module is configured to: for each piece of communication data, calculating a length ratio of a data length of the communication data to a storage length, wherein the data parameter information comprises the length ratio;
the judging module is used for: determining a maximum length ratio of the calculated length ratios; and if the maximum length ratio is larger than a preset maximum ratio threshold, determining that the preset parameter condition is met.
Optionally, the determining module is configured to: the length ratios obtained by calculation are arranged from small to large, and a first length ratio positioned in a first preset percentile is determined; and if the maximum length ratio is not greater than a preset maximum ratio threshold and the first length ratio is not in a preset percentile ratio range, determining that the preset parameter condition is met.
Optionally, the apparatus further comprises: the length determining module is used for determining the storage length to be selected according to the parameter information and the first storage length of the first shared memory area currently used by the sending end and the receiving end;
a length setting module for: if the storage length to be selected is smaller than the first storage length, setting the newly allocated second shared memory area as the storage length to be selected; if the to-be-selected storage length is not smaller than the first storage length and the to-be-selected storage length is not larger than a preset storage threshold length, setting the newly allocated second shared memory area as the to-be-selected storage length; and if the length of the storage to be selected is not less than the first storage length and is greater than a preset storage threshold length, setting the newly allocated second shared memory area as the storage threshold length.
Optionally, the length determining module is configured to: determining a target coefficient according to the parameter information; and determining the storage length to be selected according to the product of the target coefficient and the first storage length.
Optionally, the obtaining module is configured to: for each piece of communication data, calculating a length ratio of a data length of the communication data to a storage length, wherein the data parameter information comprises the length ratio;
the length determination module is configured to: determining a maximum length ratio of the calculated length ratios; the length ratios obtained by calculation are arranged from small to large, and a second length ratio positioned in a second preset percentile is determined; if the maximum length ratio and the second length ratio are not larger than a preset floating point threshold, setting a target coefficient as the second length ratio; and if any one of the maximum length ratio and the second length ratio is larger than the preset floating point threshold, setting the target coefficient as the ratio of the maximum length ratio to the floating point threshold.
Optionally, the length determining module is configured to determine the storage length to be selected as a value rounded up by a product of the target coefficient and the first storage length.
A computer-readable storage medium, on which a computer program is stored which, when being executed by a processor, carries out the steps of any of the methods for switching a shared memory area.
An electronic device, comprising: a memory having a computer program stored thereon; a processor for executing the computer program in the memory to implement the steps of any of the methods for switching a shared memory region.
The technical scheme can at least realize the following technical effects: whether the shared memory area used for communication between the sending end and the receiving end is switched is determined by judging whether the data parameter information of the communication data sent historically meets preset parameter conditions or not, and therefore the operation of switching the shared memory area can be flexibly triggered according to the data parameter information, the triggered switching of the shared memory area is enabled to meet actual operation requirements, and balance among operation cost, host resource utilization and user use physical examination is reasonably achieved.
Additional features and advantages of the disclosure will be set forth in the detailed description which follows.
Drawings
The accompanying drawings, which are included to provide a further understanding of the disclosure and are incorporated in and constitute a part of this specification, illustrate embodiments of the disclosure and together with the description serve to explain the disclosure without limiting the disclosure. In the drawings:
fig. 1 is a flowchart illustrating a method for switching a shared memory area according to an exemplary embodiment.
Fig. 2 is a flowchart illustrating a method for switching a shared memory area according to an exemplary embodiment.
Fig. 3 is a flowchart illustrating a method for switching a shared memory area according to an exemplary embodiment.
Fig. 4 is a flowchart illustrating a method for switching a shared memory area according to an exemplary embodiment.
Fig. 5 is a flowchart illustrating a method for switching a shared memory area according to an exemplary embodiment.
Fig. 6 is a flowchart illustrating a method for switching a shared memory area according to an exemplary embodiment.
Fig. 7 is a flowchart illustrating a method for switching a shared memory area according to an exemplary embodiment.
Fig. 8 is a flowchart illustrating a method for switching a shared memory area according to an exemplary embodiment.
Fig. 9 is a flowchart illustrating a method for switching a shared memory area according to an exemplary embodiment.
Fig. 10 is a block diagram illustrating an apparatus for switching a shared memory area according to an example embodiment.
Fig. 11 is a block diagram illustrating an apparatus for switching a shared memory area according to an example embodiment.
Fig. 12 is a block diagram illustrating an apparatus for switching a shared memory region according to an example embodiment.
FIG. 13 is a block diagram of an electronic device shown in accordance with an example embodiment.
FIG. 14 is a block diagram of an electronic device shown in accordance with an example embodiment.
Detailed Description
The following detailed description of specific embodiments of the present disclosure is provided in connection with the accompanying drawings. It should be understood that the detailed description and specific examples, while indicating the present disclosure, are given by way of illustration and explanation only, not limitation.
Some schemes are proposed in the related art to reduce the frequency of interaction between a virtual sending end and a virtual receiving end operating in a host during one-time data sending. For example, a larger shared memory region is allocated within the host. This has the disadvantage that when there are many VM-VM pairs or VM-Host pairs on the Host that need to communicate through the shared memory, allocating a large memory for each VM-VM pair or VM-Host pair may result in insufficient memory of the Host, which may seriously affect the performance of the Host. Moreover, such allocation strategies can be very wasteful of memory when the length of the VM-VM pair, or VM-Host pair, for transferring data is less than the length of the allocated shared memory region.
Another method is to allocate a shared memory area with the same length as the transmitted data length for each data transmission. Such an approach also introduces new technical problems. Each reallocation of a shared memory area introduces the following steps: releasing the old shared memory area, deleting the device/dev/shm 1a in the virtual machine 1 and the device/dev/shm 2b in the virtual machine 2, allocating a new shared memory area, and inserting new devices (for example, dev/shm1a _ new and dev/shm2b _ new) into the virtual machine 1 and the virtual machine 2 respectively. In this regard, if a new shared memory region is allocated for each communication, the cost (overhead) of repeating the above steps frequently is very high.
In view of the above, the present disclosure provides a method for switching a shared memory area, so as to switch the shared memory area more flexibly and improve performance of a virtual sending end and a virtual receiving end in communication based on a host shared memory area.
Fig. 1 is a flowchart illustrating a method for switching a shared memory area according to an exemplary embodiment. As shown in fig. 1, the method includes:
when the sending end sends communication data to the receiving end based on the first shared memory area, the following operations are executed:
s11, the sending end compares the data length of the communication data with the first storage length of the first shared memory area;
s12, if the data length is greater than the first storage length, the sending end writes the first sub-data segment of the communication data into the first shared memory area, and notifies the receiving end to receive the first sub-data segment from the first shared memory area, where the data length of the first sub-data segment is not greater than the first storage length.
It should be noted that, if the data length is not greater than the first storage length, all the communication data are written into the first shared memory area, and a receiving end is notified to receive the communication data from the first shared memory area.
In an example, a first storage length of the first shared memory area is denoted by s, and a data length of communication data that needs to be sent to the receiving end by the sending end at this time is denoted by n. The address of the first shared memory area is shm. In order to fully utilize the shared memory area, the data length of the first sub-data segment sent this time may be set to be equal to the storage length of the first shared memory area, that is, the data length of the first sub-data segment sent this time is s. In specific operation, when i is equal to 0, the sending end copies the data of buf [ i, i + s-1] to the address shm [0, s-1] of the shared memory area.
S13, the sending end responds to the event that the receiving end finishes receiving the first subdata segment, and detects whether the first identification is true; the first identifier is set to true when the host allocates a new second shared memory area to the sending end and the receiving end, and the first identifier is set to false when the host detects an event for representing that the sending end and the receiving end are switched to the second shared memory area.
Specifically, the event that represents that the receiving end completes receiving the first sub-data segment may be: the sending end periodically detects whether the receiving end receives the first subdata segment or not, and obtains a detection result for determining that the receiving end receives the first subdata segment.
Optionally, the receiving end may check whether there is data waiting for reception through a control channel, and copy the data of the shm [0, s-1] in the first shared memory area to its own buffer buf [0, s-1] if it is detected that there is data written in the first shared memory area. Further, the receiving end notifies the transmitting end that the data has been received through the control channel.
Specifically, since the first sub-data segment is sent, the length of the data which is not transmitted in the communication data is n-s. The transmitting end updates i to i + s, (i ═ i + s, and n ═ n-s).
Specifically, the first identifier may be set by the host. If the host completes the operation of allocating the new shared memory area, the first identifier is set to true by the assumption. It should be noted that the true/false of the first identifier is only an exemplary description. In particular implementation, the function of the first identifier may be implemented by other equivalent alternatives. For example, the first identifier is set to a different serial number, etc.
S14, if the sending end detects that the first identifier is true, the sending end performs an operation of switching to the second shared memory area, and sends a data segment of the communication data, excluding the first sub-data segment, to the receiving end based on the second shared memory area.
The technical effects of the scheme at least can be achieved as follows:
if the data length of the communication data transmitted to the receiving end by the sending end based on the shared memory area is larger than the storage length of the shared memory area, the sending end can send part of the sub-data segments to the receiving end based on the shared memory area, then the true/false state of the first identifier is detected, if the first identifier is set to be true by the host, the host is indicated to finish the operation of setting a new shared memory area, and the sending end and the receiving end can be switched to the newly allocated shared memory area to finish the operation of sending the rest communication data. Therefore, the communication data transmission performance can be improved by switching to a new shared memory area while the transmitting end is ensured not to suspend transmitting the communication data.
Generally, the newly allocated shared memory area is more suitable for the data transmission requirements of the sending end and the receiving end, when the storage length of the originally used shared memory area is short and the data length of the communication data is long, compared with an offline switching scheme for switching the shared memory area after the communication data is transmitted, the scheme can shorten the waiting time for switching to the new shared memory area, so that the residual data segment is transmitted based on the new shared memory area, and the data transmission efficiency is improved.
In an optional embodiment, the method further comprises: if the sending end is switched to the second shared memory area, a second identifier is modified to be true; the host detects an event for representing that the sending end and the receiving end are switched to the second shared memory area, and the event comprises the following steps: the host detects that the second identification is true.
Further, the method further comprises: the second identifier is set to false when the host detects an event for characterizing the switch of the sending end and the receiving end to the second shared memory area.
In addition, when it is determined that both the first flag and the second flag are set to false, the first shared memory area is released.
In order to show the above technical solutions more clearly, the following steps performed from the host, the sending end, and the receiving end are described as an example.
As shown in fig. 2, the host may perform the following steps:
in the initial state, the first flag is set to false (flag1 is false), and the second flag is set to false (flag2 is false);
judging whether a shared memory area for data communication between a sending end and a receiving end is switched;
if switching, applying for distributing a new shared memory region shm _ new;
if the new shared memory region shm _ new is completely allocated, setting the first identifier to be true (flag1 is true);
detecting whether the second flag is true (flag 2;
if the second flag is true (flag2 is true), setting the first flag to false (flag1 is false), and setting the second flag to false (flag2 is false);
and releasing the original shared memory area.
Wherein, the first mark can be used for indicating that the shared memory area is completely allocated; the second identifier may be used to indicate that the sender and the receiver complete the operation of switching to the new shared memory area.
As shown in fig. 3, when the sending end sends communication data to the receiving end based on the shared memory area, the sending end may perform the following operations:
wherein, shm is the initial address of the shared memory area currently used; s is the storage length of the shared memory area currently used; n is the data length of the communication data to be transmitted;
comparing whether n is smaller than s, namely comparing the data length of the communication data with the storage length of the currently used shared memory area;
if n is not less than s, the following operations are executed:
copying the data of buf [ i, i + s-1] to an address shm [0, s-1] of the shared memory area, wherein the buf [ i, i + s-1] can be interpreted as a sub-data segment with the data length of s;
informing a receiving end to receive data with the length of s from the shm;
circularly detecting whether the receiving end completes data receiving;
if the receiving end finishes data receiving, setting the addresses of the rest communication data needing to be transmitted, namely i is i + s, and n is n-s;
detecting whether the first flag is true, i.e., flag1 is true;
if the first identifier is true, executing an operation of switching to a new shared memory area, namely setting shm as an address shm _ new of the new shared memory area, and setting s as the storage length of the new shared memory area;
modifying the second identification to true;
if the first identifier is false, further judging whether the length of the remaining communication data to be transmitted is smaller than the length of the shared memory area, namely, repeatedly executing the step of comparing whether n is smaller than s;
if n is less than s and n is greater than 0, performing the following operations:
copying the data of buf [ i, i + s-1] to an address shm [0, s-1] of the shared memory area, wherein the buf [ i, i + s-1] can be interpreted as a sub-data segment with the data length of s;
informing a receiving end to receive data with the length of s from the shm;
circularly detecting whether the receiving end completes data receiving;
if the receiving end finishes receiving the data, the process is finished.
As shown in fig. 4, the receiving end may perform the following operations:
checking whether data waiting for receiving exists or not through a control channel cycle;
if the data exists, copying the data of the shm [0, s-1] in the shared memory area to the buf [0, s-1] of the cache area;
the transmitting end is informed through the control channel that the data has been received.
It should be noted that, the above-mentioned steps executed by each end are respectively illustrated in flowcharts, and in specific implementation, the flowcharts in fig. 2, fig. 3 and fig. 4 may be used in cooperation with each other, so as to ensure that the sending end does not suspend sending the communication data, and at the same time, improve the transmission performance of the communication data by switching to a new shared memory area.
It should be noted that if the switching of the shared memory area is triggered at a high frequency, the sending end and the receiving end may repeatedly execute the corresponding operation of switching the shared memory area at a high frequency, which results in a high operation cost. If the switching of the shared memory area is triggered at a low frequency, the current shared memory area may have a short storage length, and when larger communication data needs to be transmitted, the shared memory area cannot be switched to a shared memory area with an appropriate size in time, so that the data transmission efficiency is low; it is also possible that when the current shared memory area has a large storage length and only transmits small communication data for a long time, the adverse effects such as wasting the memory resources of the host and reducing the performance of the host occur.
In view of the above, another method for switching a shared memory area is provided in the embodiments of the present disclosure, so as to trigger switching of the shared memory area more flexibly. As shown in fig. 5, the method includes:
and S51, acquiring data parameter information of the communication data sent by the sending end in history.
The data parameters may include a time t for sending the communication data, a data length n of the communication data, and a storage length s of the shared memory area for transmitting the communication data. In addition, the data parameter information may further include a length ratio x between the data length of the communication data sent each time and the storage length of the shared memory area. This length ratio can be understood as a floating point number, i.e. based on the shared memory area with storage length s, the communication data with transmission length n needs x ═ n/s times of effective transmission to complete the transmission of the communication data.
In an optional implementation manner, each sending end may send data parameter information of the communication data sent this time to the host. Specifically, the table may be transmitted in the form of a transmission log. For example, in the log format as shown in table 1.
TABLE 1
t n s x
16:00 10 100 0.1
Specifically, at time 16:00, the length of the communication data to be transmitted is 10, the storage length of the current shared memory area is 100, and the length ratio is 0.1, so that the communication data can be transmitted through 0.1 (rounding up to 1) transmission operations. For another example, if the length of the communication number to be transmitted is 220, the storage length of the current shared memory area is 100, and the length ratio is 2.2 at time 16:20, then the communication data transmission can be completed through 2.2 (rounding up to 3) transmission operations.
It should be noted that the above log format is only an exemplary illustration. In specific implementation, the data parameters can be transmitted by using a log format with any format.
In addition, the length ratio is not a necessary transmission parameter, for example, the host may obtain the data length n and the storage length s through a log of the sending end, and then calculate the length ratio x. That is, whether the sender or the host itself, knowing the data length n and the storage length s, the following operations can be performed: and calculating the length ratio of the data length of the communication data to the storage length aiming at each communication data.
And S52, judging whether the data parameter information meets the preset parameter condition.
It should be noted that when x is much smaller than 1, for example, n is 100, s is 1000000, and x is 0.0001, it indicates that the current usage efficiency of the shared memory area is very low, and there is a need to reduce the storage length of the shared memory area. When x is much larger than 1, for example, n is 1000000, s is 100, and x is 10000, it indicates that the current shared memory area is used too frequently, and there is a need to increase the length of the shared memory area. Whether the storage length is increased or decreased, an operation of switching the shared memory area needs to be triggered.
In an optional implementation manner, the determining whether the data parameter information meets a preset parameter condition includes: determining a maximum length ratio of the calculated length ratios; and if the maximum length ratio is larger than a preset maximum ratio threshold, determining that the preset parameter condition is met.
The maximum length ratio represents the maximum transmission times (floating point numbers) encountered when the communication data is transmitted after the shared memory area is switched last time. The maximum ratio threshold may be set according to an actual use condition of a user, for example, for transmission of one communication data, the communication data is divided into 5 times and sequentially written into the shared memory for transmission for 5s, and this time is a tolerance limit of the user, so that the maximum ratio threshold may be set to 4, thereby avoiding a problem of transmitting the communication data overtime.
In another optional implementation manner, the determining whether the data parameter information meets a preset parameter condition further includes: the length ratios obtained by calculation are arranged from small to large, and a first length ratio positioned in a first preset percentile is determined; and if the maximum length ratio is not greater than a preset maximum ratio threshold and the first length ratio is not in a preset percentile ratio range, determining that the preset parameter condition is met.
Wherein, the percentile represents: a group of n values is arranged according to the numerical value, and the value at the p% position is called the p percentile. For example, the 50 percentile is the median.
In this alternative embodiment, the percentile is more statistically representative, and can more objectively reflect whether there is a need to switch the shared memory area. A comparison is made below from the example with specific values and other calculation means.
Considering the communication data sent aiming at the history, the following 4 length ratios x are obtained by calculation and are arranged in the order from small to large, wherein the length ratios x are respectively as follows: 0.01,0.01,0.01, 1000000.
The arithmetic mean (0.01, 0.01, 0.01, 1000000) ═ 250000.0075;
geometric mean (0.01, 0.01, 0.01, 1000000) ═ 1;
75 percentile (0.01, 0.01, 0.01, 1000000) to 0.01;
wherein 75 percentiles indicate that 75% of the numbers are all equal to or less than 0.01. It follows that the percentile given is more representative of the sample. The decision making based on percentiles can take most values into account, and is not as susceptible to the influence of a certain huge value on the whole as the average algorithm.
In the above optional embodiment, the representative parameters are selected for comparison and determination, so that the subsequent triggering and switching of the shared memory area can better meet the actual use requirement, and the performance of communication based on the shared memory area is further improved.
And S53, if the preset parameter conditions are met, generating an instruction for indicating to switch the shared memory area used by the sending end and the receiving end.
The technical scheme can at least realize the following technical effects:
whether the shared memory area used for communication between the sending end and the receiving end is switched is determined by judging whether the data parameter information of the communication data sent historically meets preset parameter conditions or not, and therefore the operation of switching the shared memory area can be flexibly triggered according to the data parameter information, the triggered switching of the shared memory area is enabled to meet actual operation requirements, and balance among operation cost, host resource utilization and user use physical examination is reasonably achieved.
In order to show the above technical solutions more clearly, the following steps executed from both sides of the host and the sending end are exemplified.
As shown in fig. 6, the steps that may be performed by the transmitting end include:
acquiring current time t, data length n of communication data to be transmitted, storage length s of a current shared memory area and length ratio x being n/s;
writing the data parameters t, n, s and x into a transmission log record;
and executing the operation of sending the communication data, namely writing the communication data into the shared memory area, and informing a receiving end of receiving the communication data from the shared memory area.
That is, the length of all the data transmitted in history, the storage length of the shared memory area, and the length ratio (effective transmission times) can be recorded by the step of generating the transmission log inserted in the transmission flow.
As shown in fig. 7, the steps that may be performed by the host include:
the target time length (t1-t0) from the time t1 of last time of switching the shared memory area used by the sender and the receiver to the current time t 0;
judging whether the target duration (t1-t0) is greater than a preset duration threshold value or not;
if the target duration is greater than a preset duration threshold, acquiring data parameter information of communication data which are sent by the sending end in the target duration in a historical mode, wherein the preset duration threshold can be set by a user according to actual implementation requirements, and the data parameter information comprises a length ratio x of a data length n of the communication data to a storage length s;
determining a maximum length ratio ymax in the calculated length ratios; the length ratios obtained by calculation are arranged from small to large, and a first length ratio y located in a first preset percentile is determined;
if the maximum length ratio ymax is larger than a preset maximum ratio threshold TXMax, determining that the preset parameter condition is met;
if the maximum length ratio ymax is not larger than a preset maximum ratio threshold TXMax and the first length ratio y is not in a preset percentile ratio range (a < y < b), determining that the preset parameter condition is met;
and if the preset parameter conditions are met, generating an instruction for indicating to switch the shared memory area used by the sending end and the receiving end.
It is noted that in this embodiment, too frequent length adjustment of the shared memory area is prevented by determining (t0-t1) whether the length is greater than the preset length threshold. The preset time length threshold value can be freely adjusted by a user, so that the frequency of adjusting the length of the shared memory area is determined according to the requirement of the user.
TXmax is a maximum transmission number preset by the user, for example 10000, and the main purpose of this judgment is to avoid the situation that the transmission of the communication data is too long, which results in the need of transmitting too many times. The user can adjust the maximum number of transmissions that can be tolerated by setting TXmax.
Where a < y < b (a and b are the lower and upper bounds, respectively, of the effective transmission times preset by the user), this determination may avoid frequent small-scale adjustments to the shared memory region length, and a and b are the lower and upper bounds, respectively, of the tolerable effective transmission times preset by the user. The user can control the frequency of the length adjustment of the shared memory area by adjusting a and b.
It should be noted that, it is determined that the shared memory area needs to be switched, and a proper storage length needs to be allocated to the shared memory area, so that occupation of host resources due to allocation of an excessively large shared memory area is avoided.
As shown in fig. 8, another method for switching a shared memory area according to an embodiment of the present disclosure is shown, where the method includes:
and S81, acquiring data parameter information of the communication data sent by the sending end in history.
The data parameters may include a time t for sending the communication data, a data length n of the communication data, and a storage length s of the shared memory area for transmitting the communication data.
In addition, the data parameter information may further include a length ratio x between the data length of the communication data sent each time and the storage length of the shared memory area. This length ratio can be understood as a floating point number, i.e. based on the shared memory area with storage length s, the communication data with transmission length n needs x ═ n/s times of effective transmission to complete the transmission of the communication data.
In an optional implementation manner, each sending end may send data parameter information of the communication data sent this time to the host. Specifically, the table may be transmitted in the form of a transmission log.
Specifically, at time 16:00, the length of the communication data to be transmitted is 10, the storage length of the current shared memory area is 100, and the length ratio is 0.1, so that the communication data can be transmitted through 0.2 (rounding up to 1) transmission operations. For another example, if the length of the communication number to be transmitted is 220, the storage length of the current shared memory area is 100, and the length ratio is 2.2 at 16:20, then the communication data transmission can be completed through 2.2 (rounding up to 3) transmission operations.
It should be noted that the above log format is only an exemplary illustration. In specific implementation, the data parameters can be transmitted by using a log format with any format.
In addition, the length ratio is not a necessary transmission parameter, for example, the host may obtain the data length n and the storage length s through a log of the sending end, and then calculate the length ratio x. That is, whether the sender or the host itself, knowing the data length n and the storage length s, the following operations can be performed: and calculating the length ratio of the data length of the communication data to the storage length aiming at each communication data.
And S82, determining the storage length to be selected according to the parameter information and the first storage length of the first shared memory area currently used by the sending end and the receiving end.
S83, if the storage length to be selected is smaller than the first storage length, setting the newly allocated second shared memory area as the storage length to be selected.
That is, if the obtained storage length to be selected is smaller than the currently used shared memory area, the length of the newly allocated shared memory area is the storage length to be selected. Therefore, the occupation of the host can be properly reduced while the data communication efficiency of the sending end and the receiving end is ensured.
S84, if the length of the to-be-selected memory is not less than the first memory length, and the length of the to-be-selected memory is not greater than a preset memory threshold length, setting the newly allocated second shared memory area as the length of the to-be-selected memory.
S85, if the length of the to-be-selected memory is not less than the first memory length, and the length of the to-be-selected memory is greater than a preset memory threshold length, setting the newly allocated second shared memory area as the memory threshold length.
Wherein arrows shown as dotted lines in the figure indicate selective execution according to the satisfied condition. That is, according to the value range where the storage length to be selected is actually located, it is determined to execute any one of the steps S83, S84, and S85.
In specific implementation, when the length of the storage to be selected is not smaller than the first storage length, it may be determined whether the length of the storage to be selected is larger than a preset storage threshold length. And if the length of the storage threshold is not larger than the length of the preset storage threshold, allocating a new shared memory area according to the length of the storage to be selected. And if the length of the second shared memory area is larger than the storage threshold length, only setting the newly allocated second shared memory area as the storage threshold length. Therefore, the length of the shared memory area can be ensured not to exceed the maximum value set by a user, so that the occupation of the shared memory area on the host memory is ensured to be controllable, and the performance of the host computer is not greatly influenced.
As shown in fig. 9, another method for switching a shared memory area according to an exemplary embodiment of the present disclosure is shown, where the method includes:
and aiming at each communication data, calculating the length ratio of the data length of the communication data to the storage length, wherein the data parameter information comprises the length ratio.
Determining a maximum length ratio of the calculated length ratios; and arranging the obtained length ratios from small to large, and determining a second length ratio positioned at a second preset percentile.
And respectively judging the size relation between the maximum length ratio and the second length ratio and a preset floating point threshold value.
And if the maximum length ratio and the second length ratio are not greater than a preset floating point threshold, setting a target coefficient as the second length ratio.
And if any one of the maximum length ratio and the second length ratio is larger than the preset floating point threshold, setting the target coefficient as the ratio of the maximum length ratio to the floating point threshold.
And determining the storage length to be selected as a value rounded up by the product of the target coefficient and the first storage length.
And if the storage length to be selected is smaller than the first storage length, setting the newly allocated second shared memory area as the storage length to be selected.
And if the length of the storage to be selected is not less than the first storage length and the length of the storage to be selected is not greater than the length of a preset storage threshold, setting the newly allocated second shared memory area as the length of the storage to be selected.
And if the length of the storage to be selected is not less than the first storage length and is greater than a preset storage threshold length, setting the newly allocated second shared memory area as the storage threshold length.
Specifically, the rounding-up may be represented by a ceil function. For example: ceil (0.9) ═ 1, ceil (100.1) ═ 101, and ceil (100) ═ 100.
The second predetermined percentile is assumed to be p%. If neither the maximum length ratio value nor the second length ratio value is greater than a preset floating point threshold value, that is, (y < ═ TXmax) and (ymax < ═ TXmax). After the last adjustment of the length of the shared memory area, the number of data transmission times does not exceed the preset floating point threshold TXmax, which means that the last adjustment of the length of the shared memory area does not need to consider the situation that the number of data transmission times is too large. In this case, setting the target coefficient k to the second length ratio y and setting the length of the new shared memory area to s _ new _ ceil (s × k) may enable p% of data transmission to be completed at one time.
If either the maximum length ratio value or the second length ratio value is greater than the preset floating point threshold value, i.e., (y < ═ TXmax) and (ymax < ═ TXmax) do not hold, and (y > TXmax) or (ymax > TXmax) hold. Since (ymax > ═ y) is always true, (ymax > TXmax) is always true. This means that after the last adjustment of the length of the shared memory area, at least one data transmission time exceeds TXmax, which means that the adjustment of the length of the shared memory area needs to consider the condition that the transmission time is too large. In this case, the target coefficient k is set to the second length ratio ymax/TXmax, and the length of the new shared memory area is set to s _ new _ ceil (s × ymax/TXmax), so that the number of data transmission times does not exceed TXmax even when the communication data to be transmitted is maximum.
In addition, the length of the shared memory area can be ensured not to exceed the maximum value set by a user, so that the occupation of the shared memory area on the host memory is ensured to be controllable, and the performance of the host computer is not greatly influenced.
Another method for switching a shared memory area is shown in an exemplary embodiment of the present disclosure. The method comprises the following steps: acquiring data parameter information of communication data historically sent by the sending end; judging whether the data parameter information meets preset parameter conditions or not; and if the preset parameter conditions are met, generating an instruction for indicating to switch the shared memory area used by the sending end and the receiving end.
Further, the storage length of the newly allocated shared memory area is set based on the following steps: determining a storage length to be selected according to the parameter information and a first storage length of a first shared memory area currently used by the sending end and the receiving end; if the storage length to be selected is smaller than the first storage length, setting a newly allocated second shared memory area as the storage length to be selected; if the maximum length ratio and the second length ratio are not larger than a preset floating point threshold, setting a target coefficient as the second length ratio; if any one of the maximum length ratio and the second length ratio is larger than the preset floating point threshold, setting the target coefficient as the ratio of the maximum length ratio to the floating point threshold; a first flag indicating that allocation of the new second shared memory region is completed is set to true.
Further, when the sending end sends the communication data to the receiving end based on the first shared memory area, the following operations are executed: comparing the data length of the communication data with the first storage length of the first shared memory area; if the data length is greater than the first storage length, writing a first sub data segment of the communication data into the first shared memory area, and informing the receiving end of receiving the first sub data segment from the first shared memory area, wherein the data length of the first sub data segment is not greater than the first storage length; the sending end responds to an event representing that the receiving end finishes receiving the first sub data segment, and detects whether a first identifier is true; the first identifier is set to true when the host allocates a new second shared memory area to the sending end and the receiving end, and the first identifier is set to false when the host detects an event for representing that the sending end and the receiving end are switched to the second shared memory area. And if the sending end detects that the first identifier is true, the sending end executes the operation of switching to the second shared memory area, and sends data segments, except the first subdata segments, in the communication data to the receiving end based on the second shared memory area.
In the above scheme, whether to switch to a new shared memory area may be determined by using data parameters of the communication data sent by the sending end historically, the size of the new shared memory area is flexibly set based on the data parameters when determining to allocate the new shared memory area, and the sending end is enabled to realize non-suspended switching to the newly allocated shared memory area during sending the communication data based on the previous shared memory area by setting the first identifier, so that the performance of data communication based on the host shared memory area is improved as a whole.
Another method for switching a shared memory area is shown in an exemplary embodiment of the present disclosure. The method comprises the following steps: acquiring data parameter information of communication data historically sent by the sending end; judging whether the data parameter information meets preset parameter conditions or not; and if the preset parameter conditions are met, generating an instruction for indicating to switch the shared memory area used by the sending end and the receiving end.
Further, the storage length of the newly allocated shared memory area is set based on the following steps:
determining a storage length to be selected according to the parameter information and a first storage length of a first shared memory area currently used by the sending end and the receiving end;
if the storage length to be selected is smaller than the first storage length, setting a newly allocated second shared memory area as the storage length to be selected;
if the maximum length ratio and the second length ratio are not larger than a preset floating point threshold, setting a target coefficient as the second length ratio;
and if any one of the maximum length ratio and the second length ratio is larger than the preset floating point threshold, setting the target coefficient as the ratio of the maximum length ratio to the floating point threshold.
In the above scheme, whether to switch to a new shared memory area can be determined by sending data parameters of communication data historically sent by the sending end, and the size of the new shared memory area is flexibly set based on the data parameters when determining to allocate the new shared memory area, so that the performance of data communication based on the host shared memory area is integrally improved.
Fig. 10 is a block diagram of an apparatus 1000 for switching a shared memory region according to the present disclosure. The shared memory area is positioned on a host, and a virtual sending end and a virtual receiving end run on the host; the apparatus 1000 comprises:
a sending module 1010, configured to execute the following operations when the sending end sends communication data to the receiving end based on the first shared memory area: comparing the data length of the communication data with the first storage length of the first shared memory area; if the data length is greater than the first storage length, writing a first sub data segment of the communication data into the first shared memory area, and informing the receiving end of receiving the first sub data segment from the first shared memory area, wherein the data length of the first sub data segment is not greater than the first storage length;
a detecting module 1020, configured to detect, by the sending end, whether a first identifier is true in response to an event that characterizes that the receiving end completes receiving the first sub data segment; the first identifier is set to be true when the host allocates a new second shared memory area for the sending end and the receiving end, and the first identifier is set to be false when the host detects an event for representing that the sending end and the receiving end are switched to the second shared memory area;
a switching module 1030, configured to execute an operation of switching to the second shared memory area if the sending end detects that the first identifier is true, and send a data segment, excluding the first sub-data segment, in the communication data to the receiving end based on the second shared memory area.
The technical effects of the scheme at least can be achieved as follows: if the data length of the communication data transmitted to the receiving end by the sending end based on the shared memory area is larger than the storage length of the shared memory area, the sending end can send part of the sub-data segments to the receiving end based on the shared memory area, then the true/false state of the first identifier is detected, if the first identifier is set to be true by the host, the host is indicated to finish the operation of setting a new shared memory area, and the sending end and the receiving end can be switched to the newly allocated shared memory area to finish the operation of sending the rest communication data. Therefore, the communication data transmission performance can be improved by switching to a new shared memory area while the transmitting end is ensured not to suspend transmitting the communication data.
Optionally, the switching module is configured to: if the sending end is switched to the second shared memory area, a second identifier is modified to be true; and the host detects an event for representing that the sending end and the receiving end are switched to the second shared memory area, including that the host detects that the second identifier is true.
Optionally, the switching module is configured to: the second identifier is set to false when the host detects an event for characterizing the switch of the sending end and the receiving end to the second shared memory area.
Optionally, the apparatus further comprises:
the acquisition module is used for acquiring data parameter information of communication data which is historically sent by the sending end;
the judging module is used for judging whether the data parameter information meets a preset parameter condition or not;
and the triggering module is used for generating an instruction for indicating the switching of the shared memory area used by the sending end and the receiving end if the preset parameter condition is met.
Optionally, the apparatus further comprises a time module configured to: the target duration between the time of executing the switching of the shared memory area used by the sending end and the receiving end for the last time and the current time is calculated;
the obtaining module is configured to: and if the target time length is greater than a preset time length threshold value, acquiring data parameter information of communication data which are sent by the sending end in the target time length in a historical mode.
Optionally, the obtaining module is configured to: for each piece of communication data, calculating a length ratio of a data length of the communication data to a storage length, wherein the data parameter information comprises the length ratio;
the judging module is used for: determining a maximum length ratio of the calculated length ratios; and if the maximum length ratio is larger than a preset maximum ratio threshold, determining that the preset parameter condition is met.
Optionally, the determining module is configured to: the length ratios obtained by calculation are arranged from small to large, and a first length ratio positioned in a first preset percentile is determined; and if the maximum length ratio is not greater than a preset maximum ratio threshold and the first length ratio is not in a preset percentile ratio range, determining that the preset parameter condition is met.
Optionally, the apparatus further comprises: the length determining module is used for determining the storage length to be selected according to the parameter information and the first storage length of the first shared memory area currently used by the sending end and the receiving end;
a length setting module for: if the storage length to be selected is smaller than the first storage length, setting the newly allocated second shared memory area as the storage length to be selected; if the to-be-selected storage length is not smaller than the first storage length and the to-be-selected storage length is not larger than a preset storage threshold length, setting the newly allocated second shared memory area as the to-be-selected storage length; and if the length of the storage to be selected is not less than the first storage length and is greater than a preset storage threshold length, setting the newly allocated second shared memory area as the storage threshold length.
Optionally, the length determining module is configured to: determining a target coefficient according to the parameter information; and determining the storage length to be selected according to the product of the target coefficient and the first storage length.
Optionally, the obtaining module is configured to: for each piece of communication data, calculating a length ratio of a data length of the communication data to a storage length, wherein the data parameter information comprises the length ratio;
the length determination module is configured to: determining a maximum length ratio of the calculated length ratios; the length ratios obtained by calculation are arranged from small to large, and a second length ratio positioned in a second preset percentile is determined; if the maximum length ratio and the second length ratio are not larger than a preset floating point threshold, setting a target coefficient as the second length ratio; and if any one of the maximum length ratio and the second length ratio is larger than the preset floating point threshold, setting the target coefficient as the ratio of the maximum length ratio to the floating point threshold.
Optionally, the length determining module is configured to determine the storage length to be selected as a value rounded up by a product of the target coefficient and the first storage length.
Fig. 11 is a block diagram illustrating an apparatus 1100 for switching a shared memory area according to the present disclosure. The shared memory area is positioned on a host, and a virtual sending end and a virtual receiving end run on the host; the apparatus 1100 comprises:
an obtaining module 1110, configured to obtain data parameter information of communication data sent by the sending end in history;
a determining module 1120, configured to determine whether the data parameter information meets a preset parameter condition;
a triggering module 1130, configured to generate an instruction for instructing to switch the shared memory area used by the sending end and the receiving end if the preset parameter condition is met.
The technical scheme can at least realize the following technical effects: whether the shared memory area used for communication between the sending end and the receiving end is switched is determined by judging whether the data parameter information of the communication data sent historically meets preset parameter conditions or not, and therefore the operation of switching the shared memory area can be flexibly triggered according to the data parameter information, the triggered switching of the shared memory area is enabled to meet actual operation requirements, and balance among operation cost, host resource utilization and user use physical examination is reasonably achieved.
Optionally, the apparatus further comprises a time module configured to: the target duration between the time of executing the switching of the shared memory area used by the sending end and the receiving end for the last time and the current time is calculated;
the obtaining module is configured to: and if the target time length is greater than a preset time length threshold value, acquiring data parameter information of communication data which are sent by the sending end in the target time length in a historical mode.
Optionally, the obtaining module is configured to: for each piece of communication data, calculating a length ratio of a data length of the communication data to a storage length, wherein the data parameter information comprises the length ratio;
the judging module is used for: determining a maximum length ratio of the calculated length ratios; and if the maximum length ratio is larger than a preset maximum ratio threshold, determining that the preset parameter condition is met.
Optionally, the determining module is configured to: the length ratios obtained by calculation are arranged from small to large, and a first length ratio positioned in a first preset percentile is determined; and if the maximum length ratio is not greater than a preset maximum ratio threshold and the first length ratio is not in a preset percentile ratio range, determining that the preset parameter condition is met.
Optionally, the apparatus further comprises: the length determining module is used for determining the storage length to be selected according to the parameter information and the first storage length of the first shared memory area currently used by the sending end and the receiving end;
a length setting module for: if the storage length to be selected is smaller than the first storage length, setting the newly allocated second shared memory area as the storage length to be selected; if the to-be-selected storage length is not smaller than the first storage length and the to-be-selected storage length is not larger than a preset storage threshold length, setting the newly allocated second shared memory area as the to-be-selected storage length; and if the length of the storage to be selected is not less than the first storage length and is greater than a preset storage threshold length, setting the newly allocated second shared memory area as the storage threshold length.
Optionally, the length determining module is configured to: determining a target coefficient according to the parameter information; and determining the storage length to be selected according to the product of the target coefficient and the first storage length.
Optionally, the obtaining module is configured to: for each piece of communication data, calculating a length ratio of a data length of the communication data to a storage length, wherein the data parameter information comprises the length ratio;
the length determination module is configured to: determining a maximum length ratio of the calculated length ratios; the length ratios obtained by calculation are arranged from small to large, and a second length ratio positioned in a second preset percentile is determined; if the maximum length ratio and the second length ratio are not larger than a preset floating point threshold, setting a target coefficient as the second length ratio; and if any one of the maximum length ratio and the second length ratio is larger than the preset floating point threshold, setting the target coefficient as the ratio of the maximum length ratio to the floating point threshold.
Optionally, the length determining module is configured to determine the storage length to be selected as a value rounded up by a product of the target coefficient and the first storage length.
Optionally, the apparatus further comprises a time module configured to: the target duration between the time of executing the switching of the shared memory area used by the sending end and the receiving end for the last time and the current time is calculated; the obtaining module is configured to: and if the target time length is greater than a preset time length threshold value, acquiring data parameter information of communication data which are sent by the sending end in the target time length in a historical mode.
Fig. 12 is a block diagram illustrating an apparatus 1200 for switching a shared memory region according to the present disclosure. The shared memory area is positioned on a host, and a virtual sending end and a virtual receiving end run on the host; the apparatus 1200 comprises:
an obtaining module 1210, configured to obtain data parameter information of communication data sent by the sending end in history;
a length determining module 1220, configured to determine a storage length to be selected according to the parameter information and a first storage length of a first shared memory area currently used by the sending end and the receiving end;
a length setting module 1230 to: if the storage length to be selected is smaller than the first storage length, setting the newly allocated second shared memory area as the storage length to be selected; if the to-be-selected storage length is not smaller than the first storage length and the to-be-selected storage length is not larger than a preset storage threshold length, setting the newly allocated second shared memory area as the to-be-selected storage length; and if the length of the storage to be selected is not less than the first storage length and is greater than a preset storage threshold length, setting the newly allocated second shared memory area as the storage threshold length.
The technical scheme can at least achieve the following technical effects: and if the obtained storage length to be selected is smaller than the currently used shared memory area, the length of the newly allocated shared memory area is the storage length to be selected. Therefore, the occupation of the host can be properly reduced while the data communication efficiency of the sending end and the receiving end is ensured.
And judging whether the storage length to be selected is greater than a preset storage threshold length or not by judging whether the storage length to be selected is not less than the first storage length. And if the length of the storage threshold is not larger than the length of the preset storage threshold, allocating a new shared memory area according to the length of the storage to be selected. And if the length of the second shared memory area is larger than the storage threshold length, only setting the newly allocated second shared memory area as the storage threshold length. Therefore, the length of the shared memory area can be ensured not to exceed the maximum value set by a user, so that the occupation of the shared memory area on the host memory is ensured to be controllable, and the performance of the host computer is not greatly influenced.
Optionally, the length determining module is configured to: determining a target coefficient according to the parameter information; and determining the storage length to be selected according to the product of the target coefficient and the first storage length.
Optionally, the obtaining module is configured to: for each piece of communication data, calculating a length ratio of a data length of the communication data to a storage length, wherein the data parameter information comprises the length ratio;
the length determination module is configured to: determining a maximum length ratio of the calculated length ratios; the length ratios obtained by calculation are arranged from small to large, and a second length ratio positioned in a second preset percentile is determined; if the maximum length ratio and the second length ratio are not larger than a preset floating point threshold, setting a target coefficient as the second length ratio; and if any one of the maximum length ratio and the second length ratio is larger than the preset floating point threshold, setting the target coefficient as the ratio of the maximum length ratio to the floating point threshold.
Optionally, the length determining module is configured to determine the storage length to be selected as a value rounded up by a product of the target coefficient and the first storage length.
With regard to the apparatus in the above-described embodiment, the specific manner in which each module performs the operation has been described in detail in the embodiment related to the method, and will not be elaborated here.
A computer-readable storage medium, on which a computer program is stored which, when being executed by a processor, carries out the steps of any of the methods for switching a shared memory area.
An electronic device, comprising: a memory having a computer program stored thereon; a processor for executing the computer program in the memory to implement the steps of any of the methods for switching a shared memory region.
Fig. 13 is a block diagram illustrating an electronic device 1300 in accordance with an example embodiment. For example, the electronic device 1300 may be provided as a server. Referring to fig. 13, an electronic device 1300 includes a processor 1322, which may be one or more in number, and a memory 1332 for storing computer programs that are executable by the processor 1322. The computer programs stored in memory 1332 may include one or more modules that each correspond to a set of instructions. Further, the processor 1322 may be configured to execute the computer program to perform the method for switching the shared memory area.
Additionally, the electronic device 1300 may also include a power component 1326 and a communication component 1350, the power component 1326 may be configured to perform power management for the electronic device 1300, and the communication component 1350 may be configured to enable communication, e.g., wired or wireless communication, for the electronic device 1300. The electronic device 1300 may also include input/output (I/O) interfaces 1358. The electronic device 1300 may operate based on an operating system, such as Windows Server, Mac OS XTM, UnixTM, Linux, etc., stored in memory 1332.
In another exemplary embodiment, a computer readable storage medium including program instructions which, when executed by a processor, implement the steps of the method for switching a shared memory area described above is also provided. For example, the computer readable storage medium can be the memory 1332 comprising program instructions that can be executed by the processor 1322 of the electronic device 1300 to perform the method for switching the shared memory region.
Fig. 14 is a block diagram illustrating an electronic device 1400 in accordance with an example embodiment. As shown in fig. 14, the electronic device 1400 may include: a processor 1401, and a memory 1402. The electronic device 1400 may also include one or more of a multimedia component 1403, an input/output (I/O) interface 1404, and a communication component 1405.
The processor 1401 is configured to control the overall operation of the electronic device 1400, so as to complete all or part of the steps in the method for switching the shared memory area. The memory 1402 is used to store various types of data to support operation of the electronic device 1400, such as instructions for any application or method operating on the electronic device 1400 and application-related data, such as contact data, messaging, pictures, audio, video, and the like. The Memory 1402 may be implemented by any type of volatile or non-volatile Memory device or combination thereof, such as Static Random Access Memory (SRAM), Electrically Erasable Programmable Read-Only Memory (EEPROM), Erasable Programmable Read-Only Memory (EPROM), Programmable Read-Only Memory (PROM), Read-Only Memory (ROM), magnetic Memory, flash Memory, magnetic disk, or optical disk. Multimedia components 1403 may include screen and audio components. Wherein the screen may be, for example, a touch screen and the audio component is used for outputting and/or inputting audio signals. For example, the audio component may include a microphone for receiving external audio signals. The received audio signal may further be stored in the memory 1402 or transmitted through the communication component 1405. The audio assembly also includes at least one speaker for outputting audio signals. The I/O interface 1404 provides an interface between the processor 1401 and other interface modules, such as a keyboard, mouse, buttons, etc. These buttons may be virtual buttons or physical buttons. The communication component 1405 is used for wired or wireless communication between the electronic device 1400 and other devices. Wireless communication, such as Wi-Fi, bluetooth, Near Field Communication (NFC), 2G, 3G, 4G, NB-IOT, eMTC, or other 5G, etc., or a combination of one or more of them, which is not limited herein. The corresponding communication component 14014 can thus include: Wi-Fi module, Bluetooth module, NFC module, etc.
In an exemplary embodiment, the electronic Device 1400 may be implemented by one or more Application Specific Integrated Circuits (ASICs), Digital Signal Processors (DSPs), Digital Signal Processing Devices (DSPDs), Programmable Logic Devices (PLDs), Field Programmable Gate Arrays (FPGAs), controllers, microcontrollers, microprocessors, or other electronic components for performing the above method of switching the shared memory region.
In another exemplary embodiment, a computer readable storage medium including program instructions which, when executed by a processor, implement the steps of the method for switching a shared memory area described above is also provided. For example, the computer readable storage medium may be the memory 1402 described above comprising program instructions that can be executed by the processor 1401 of the electronic device 1400 to perform the method for switching the shared memory area described above.
The preferred embodiments of the present disclosure are described in detail with reference to the accompanying drawings, however, the present disclosure is not limited to the specific details of the above embodiments, and various simple modifications may be made to the technical solution of the present disclosure within the technical idea of the present disclosure, and these simple modifications all belong to the protection scope of the present disclosure. It should be noted that, in the foregoing embodiments, various features described in the above embodiments may be combined in any suitable manner, and in order to avoid unnecessary repetition, various combinations that are possible in the present disclosure are not described again. In addition, any combination of various embodiments of the present disclosure may be made, and the same should be considered as the disclosure of the present disclosure, as long as it does not depart from the spirit of the present disclosure.

Claims (11)

1. A method for switching a shared memory area is characterized in that the shared memory area is located in a host, and a virtual sending end and a virtual receiving end run on the host; the method further comprises the following steps:
acquiring data parameter information of communication data historically sent by the sending end;
judging whether the data parameter information meets preset parameter conditions or not;
and if the preset parameter conditions are met, generating an instruction for indicating to switch the shared memory area used by the sending end and the receiving end.
2. The method of claim 1, further comprising:
the target duration between the time of executing the switching of the shared memory area used by the sending end and the receiving end for the last time and the current time is calculated;
the acquiring of the data parameter information of the communication data sent by the sending end in history includes:
and if the target time length is greater than a preset time length threshold value, acquiring data parameter information of communication data which are sent by the sending end in the target time length in a historical mode.
3. The method according to claim 1, wherein the obtaining data parameter information of the communication data sent by the sending end in history comprises:
for each piece of communication data, calculating a length ratio of a data length of the communication data to a storage length, wherein the data parameter information comprises the length ratio;
the judging whether the data parameter information meets a preset parameter condition includes:
determining a maximum length ratio of the calculated length ratios;
and if the maximum length ratio is larger than a preset maximum ratio threshold, determining that the preset parameter condition is met.
4. The method according to claim 3, wherein the determining whether the data parameter information meets a preset parameter condition further comprises:
the length ratios obtained by calculation are arranged from small to large, and a first length ratio positioned in a first preset percentile is determined;
and if the maximum length ratio is not greater than a preset maximum ratio threshold and the first length ratio is not in a preset percentile ratio range, determining that the preset parameter condition is met.
5. The method according to any one of claims 1-4, further comprising:
determining a storage length to be selected according to the parameter information and a first storage length of a first shared memory area currently used by the sending end and the receiving end;
if the storage length to be selected is smaller than the first storage length, setting a newly allocated second shared memory area as the storage length to be selected;
if the to-be-selected storage length is not smaller than the first storage length and is larger than a preset storage threshold length, setting the newly allocated second shared memory area as the to-be-selected storage length;
and if the length of the storage to be selected is not less than the first storage length and is greater than a preset storage threshold length, setting the newly allocated second shared memory area as the storage threshold length.
6. The method according to claim 5, wherein the determining a storage length to be selected is performed according to the parameter information and a first storage length of a first shared memory area currently used by the sending end and the receiving end; the method comprises the following steps:
determining a target coefficient according to the parameter information;
and determining the storage length to be selected according to the product of the target coefficient and the first storage length.
7. The method according to claim 6, wherein the obtaining data parameter information of the communication data sent by the sending end in history comprises:
for each piece of communication data, calculating a length ratio of a data length of the communication data to a storage length, wherein the data parameter information comprises the length ratio;
the determining a target coefficient according to the parameter information includes:
determining a maximum length ratio of the calculated length ratios;
the length ratios obtained by calculation are arranged from small to large, and a second length ratio positioned in a second preset percentile is determined;
if the maximum length ratio and the second length ratio are not larger than a preset floating point threshold, setting a target coefficient as the second length ratio;
and if any one of the maximum length ratio and the second length ratio is larger than the preset floating point threshold, setting the target coefficient as the ratio of the maximum length ratio to the floating point threshold.
8. The method of claim 6, wherein determining the candidate storage length based on the product of the target coefficient and the first storage length comprises:
and determining the storage length to be selected as a value rounded up by the product of the target coefficient and the first storage length.
9. A device for switching a shared memory area is characterized in that the shared memory area is located in a host, and a virtual sending end and a virtual receiving end run on the host; the device comprises:
the acquisition module is used for acquiring data parameter information of communication data which is historically sent by the sending end;
the judging module is used for judging whether the data parameter information meets a preset parameter condition or not;
and the triggering module is used for generating an instruction for indicating the switching of the shared memory area used by the sending end and the receiving end if the preset parameter condition is met.
10. A computer-readable storage medium, on which a computer program is stored which, when being executed by a processor, carries out the steps of the method according to any one of claims 1 to 8.
11. An electronic device, comprising:
a memory having a computer program stored thereon;
a processor for executing the computer program in the memory to carry out the steps of the method of any one of claims 1 to 8.
CN201910277829.9A 2019-04-08 2019-04-08 Method and device for switching shared memory area, storage medium and electronic equipment Pending CN111796944A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN201910277829.9A CN111796944A (en) 2019-04-08 2019-04-08 Method and device for switching shared memory area, storage medium and electronic equipment

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN201910277829.9A CN111796944A (en) 2019-04-08 2019-04-08 Method and device for switching shared memory area, storage medium and electronic equipment

Publications (1)

Publication Number Publication Date
CN111796944A true CN111796944A (en) 2020-10-20

Family

ID=72805422

Family Applications (1)

Application Number Title Priority Date Filing Date
CN201910277829.9A Pending CN111796944A (en) 2019-04-08 2019-04-08 Method and device for switching shared memory area, storage medium and electronic equipment

Country Status (1)

Country Link
CN (1) CN111796944A (en)

Citations (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20110131571A1 (en) * 2009-11-30 2011-06-02 Itamar Heim Mechanism for Shared Memory History Optimization in a Host Selection Algorithm for Virtual Machine Placement
US20130160005A1 (en) * 2011-12-15 2013-06-20 Electronics And Telecommunications Research Institute Apparatus and method for virtualizing input/output devices using shared memory in host-based mobile terminal virtualization environment
CN104915151A (en) * 2015-06-02 2015-09-16 杭州电子科技大学 Active sharing memory excessive allocation method in multi-virtual machine system
US20160048464A1 (en) * 2014-08-15 2016-02-18 Jun Nakajima Technologies for secure inter-virtual-machine shared memory communication
CN108829529A (en) * 2018-06-14 2018-11-16 中国平安人寿保险股份有限公司 Virutal machine memory sharing method, device, computer equipment and storage medium

Patent Citations (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20110131571A1 (en) * 2009-11-30 2011-06-02 Itamar Heim Mechanism for Shared Memory History Optimization in a Host Selection Algorithm for Virtual Machine Placement
US20130160005A1 (en) * 2011-12-15 2013-06-20 Electronics And Telecommunications Research Institute Apparatus and method for virtualizing input/output devices using shared memory in host-based mobile terminal virtualization environment
US20160048464A1 (en) * 2014-08-15 2016-02-18 Jun Nakajima Technologies for secure inter-virtual-machine shared memory communication
CN104915151A (en) * 2015-06-02 2015-09-16 杭州电子科技大学 Active sharing memory excessive allocation method in multi-virtual machine system
CN108829529A (en) * 2018-06-14 2018-11-16 中国平安人寿保险股份有限公司 Virutal machine memory sharing method, device, computer equipment and storage medium

Similar Documents

Publication Publication Date Title
US10169089B2 (en) Computer and quality of service control method and apparatus
EP3385835B1 (en) Method and apparatus for configuring accelerator
CN107832100B (en) APK plug-in loading method and terminal thereof
CN110753131A (en) Microservice distributed current limiting method and device, storage medium and electronic equipment
CN105468718B (en) Data consistency processing method, device and system
CN110209348B (en) Data storage method and device, electronic equipment and storage medium
US20210365295A1 (en) Method, storage medium storing instructions, and apparatus for implementing hardware resource allocation according to user-requested resource quantity
KR20160049006A (en) Method, apparatus, and system for managing migration of virtual machine
CN110650503B (en) Network access method, device, system and computer readable storage medium
EP3506575B1 (en) Method and device for data transmission
US20140289490A1 (en) Extended address volume (eav) allocation verification
JP2020025210A (en) Resource allocation device and resource allocation method
CN108234551B (en) Data processing method and device
US10877790B2 (en) Information processing apparatus, control method and storage medium
US11252121B2 (en) Message sending method and terminal device
CN111796901A (en) Method and device for switching shared memory area, storage medium and electronic equipment
EP3188026B1 (en) Memory resource management method and apparatus
CN116467235B (en) DMA-based data processing method and device, electronic equipment and medium
CN110489356B (en) Information processing method, information processing device, electronic equipment and storage medium
CN112631994A (en) Data migration method and system
CN111796902B (en) Method and device for switching shared memory area, storage medium and electronic equipment
CN111796944A (en) Method and device for switching shared memory area, storage medium and electronic equipment
CN116401043A (en) Execution method of computing task and related equipment
CN111857546A (en) Method, network adapter and computer program product for processing data
US10992531B2 (en) Reactive non-blocking input and output for target device communication

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination